Remove index.html from the URL

Some servers seem to automatically append index.html to all HTTP requests, which you can remove by placing this at the beginning of .htaccess:

RewriteEngine On # remove this, if you have it already

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

I used this technique for a site that I built — ichomesforsale.com which is hosted at Godaddy.

You may also like

4 Comments

`rolandinsh` Feb 22, 18:52

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

works with RewriteEngine On

Somehow Your version on my GoDaddy hosting caused Error 500 :|
This was fast work-around

Kaspars Feb 22, 19:01

rolandinsh, I think this (.*)index.html$ should cause an error because there is an unescaped . in index.html.

`rolandinsh` Feb 22, 19:21

Kaspars, If about my version, that is just fast-typing typo :) (thanks for cleaning) My mistake! Of course need to escape dots

OK, by cleaning-up made small “upgrade” too:
for both .html and .php :)
RewriteCond %{THE_REQUEST} \/index\.(php|html)\ HTTP [NC]
RewriteRule (.*)index\.(php|html)$ /$1 [R=301,L]

Kaspars Feb 22, 19:45

rolandinsh, this looks good.

Leave a Comment