Hide index.html from URL in address bar

12 December, 2012 (21:07) | htaccess, mod_rewrite | By: sblogadmin

Question: I want users to my site to always go to the base URL http://site.com/ – I never want the index page to show. For example, I want http://site.com/index.html to redirect automatically to http://site.com without the index.html

Answer:

Create a .htaccess file (or add to your existing .htaccess) in the top level directory for your site and add the following line:


RewriteEngine on

RewriteRule ^index\.html$ / [R=301,L]

The line :


RewriteEngine on

may already be in your existing .htaccess. If so, do not duplicate it.

Write a comment