Blog Redirect One Webpage Extension to Another
May 21, 2013 .htaccess, Development Social Share
However, not every page had an equivalent page created. There was no banana.php so we needed to keep banana.html as if there weren’t any rules in place.
RewriteCond %{REQUEST_FILENAME} (.*).html$
RewriteCond %1.php -f
RewriteRule ^(.*).html$ $1.php [R,L]
Stack Overflow user szemian posted a great solution that only takes three lines in the .htaccess file. The first checks to see if the requested webpage has a .html extension, the second checks if the .php page exists and the third line completes the redirect if it does.