Removing .html on paths with htaccess

I want to remove the .html off the end of all my links, for example should be

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. should be

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.