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.

4 Comments

  1. `rolandinsh` says:

    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

  2. Kaspars says:

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

  3. `rolandinsh` says:

    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]

Leave a Reply