Comment on 301 Redirect Htaccess by SEO Dave.

301 Redirect Htaccess A 301 redirect from index.html to root won’t open your directory up for all to see as long as the DirectoryIndex is set to an index.*** file that is within that directory.

Easiest way to know is test it, does loading example.com/directory/ load the same page as example.com/directory/index.html (when there’s an index.html file in that directory).

If it does it’s set. If not set it.

DirectoryIndex can be set server side (for all sites on a server) or site/directory wide via an .htaccess file.

Put something like this at the top of your .htaccess file (if it already works it’s set server side, no need to add this):

DirectoryIndex index.html index.asp index.htm index.php

Would look for index.*** until it found one of the file types above. Order the file types in order you tend to use them as the main index file, if you only use index.php for example you’d only need:

DirectoryIndex index.php

This is the sort of code you’d add to your .htaccess file to 301 redirect /index.html to /

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

This will 301 redirect the index.html pages to their respective directories.

If you are finding Google is indexing index.html and you don’t want this (It won’t after adding the 301 redirect above).

1. Stop linking to example.com/index.html, make sure all links point to example.com/

2. Setup a canonical URL within the head section of your index.html file. This is a solution if you don’t have access to your .htaccess file for adding a 301 redirect, but do have access to the page code.

<link rel="canonical" href="http://www.example.com/" />

This will tell Google when it spiders www.example.com and www.example.com/index.html the correct URL is www.example.com

A canonical URL won’t redirect a browser window from /index.html to / but the link benefit/Google rankings will be redirected (like a 301 redirect without the browser redirecting).

You can set a relevant canonical URL for any page that can be loaded two or more ways. If you have dynamic pages for example that can be loaded in different ways look into canonical URLs. I use WordPress for most of my sites now and canonical URL support is built in (automated).

David Law