Removing .html on paths with htaccess

I want to remove the .html off the end of all my links, for example www.mywebsite.com/contact.html should be www.mywebsite.com/contact

The following code does the job:

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

I also want my directory files to remove the .html too, i.e. www.mywebsite.com/rates/index.html should be www.mywebsite.com/rates

It is working with the following code:

RewriteCond %{REQUEST_URI} /index.html?$ [NC]
RewriteRule ^(.*)index.html?$ "/$1" [NC,R=301,NE,L]

But together, they don’t work. If the second sits underneath the 1st only the 1st works. If I only have the second option my 1st doesn’t work and all my links are broken. How do I combine the two?


Source: .htaccess

Leave a Reply