Jeremy Jeremy - 4 months ago 7
HTML Question

How to redirect html extension using htaccess?

At the moment, both of these links show the same page:

What I want to do is redirect all the html-type links to the non-html links.

I know this might seem simple to do with htaccess, but it's not working for me.

Here's my htaccess code so far:

RewriteEngine On
RewriteBase /

#removing trailing slash

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R=301,L]

#non www to www

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


AddType text/html .html
AddHandler server-parsed .html


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]

#index redirect

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ [R=301,L]

RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]