Reputation: 11
My website is changing URLs and will remove the file extension .html
OLD URL:
http://example.com/states.html
NEW URL:
http://example.com/states
How can I set up my .htaccess
file to do a site-wide redirect removing the .html
extension?
Upvotes: 1
Views: 142
Reputation: 1201
To redirect from .html
to extensionless URLs, try the following near the top of your .htaccess
file (before the front controller that is rewriting your "pretty" URLs).
RewriteEngine On
RewriteRule (.+)\.html$ /$1 [R=302,L]
Change the 302
(temporary) redirect to 301
(permanent) when you are sure it's working OK. 301s are cached by the browser so can make testing problematic if there is an error.
Upvotes: 1
Reputation: 1292
This should do the trick for you:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Upvotes: 0