Monday, 9 September 2013

301 Redirect *.php to *.html via .htaccess?

301 Redirect *.php to *.html via .htaccess?

Currently I'm rewriting all incoming requests for *.html to *.php in my
.htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^(.*).html$ $1.php [QSA]
ErrorDocument 404 /404.html
So /something.html is rewritten to /something.php.
However, /something.php is still directly accessible in the browser. Now I
want it to redirect to /something.html when people are accessing it in the
browser, so as to avoid 2 distinct URLs for the same page of content.
Is this possible to do in my .htaccess? How? I tried R=301 but it's always
a redirect loop or something. Any help would be appreciated. Thanks!

No comments:

Post a Comment