Duplicate content fix index.html vs / (slash only)
Web Hosting Articles »
A simple guide to .htaccess »
Duplicate content fix index.html vs / (slash only)
This similar to the www vs non-www version of your site work-around.
As you might now you, by default you can access your site as http://www.domain.com/ and http://www.domain.com/index.html with some setups it can be index.php or index.asp or default.aps, etc.
Unfortunately, this creates a risk of duplicate content from the search engine point of view. To avoid this, you can use the following ModRewrite rules in your .htaccess file:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.domain.com/ [R=301,L]
The file should be located in your website main folder (web root).
The rules above will tell the browser or the search engine both that all requests to index.html should be directed to the "/" (slash only).
- How to block users from accessing your site based on their IP address
- How to prevent or allow directory listing?
- How to change the error documents – 404 Page Not Found, etc
- Using .htaccess for password protecting your folders
- Using .htaccess to block referrer spam
- Disable Hot-Linking of images and other files
- Redirect URLs using .htaccess
- Introduction to mod_rewrite and some basic examples
- Force SSL/https using .htaccess and mod_rewrite
- 301 Permanent redirects for parked domain names
- Enable CGI, SSI with .htaccess
- How to add Mime-Types using .htaccess
- Change default directory page
- Block Bad robots, spiders, crawlers and harvesters
- Make PHP to work in your HTML files with .htacess
- Change PHP variables using .htaccess
- HTTP Authentication with PHP running as CGI/SuExec
- Force www vs non-www to avoid duplicate content on Google
- Duplicate content fix index.html vs / (slash only)
Comments 13 >>
Art Village Said,
"DirectoryIndex index.html" does not work.
Peace,
Mar 05, 2009 @ 05:19
What if you want the result to be index.html and never have a url ending in just a slash?"DirectoryIndex index.html" does not work.
Peace,
Wedding Magician - Roger Lapin Said,
Thanks
Roger
May 25, 2010 @ 16:12
Thanks for the tip I have been looking at my site and it has both / and index.html in googles index - i will get to fix this now.Thanks
Roger
Funny Man Said,
Does anyone know how to code the .htaccess to force /index.html to show?
I figure I can set a different default file with an embedded redirect to /index.html but would like this to be handled at .htaccess level
It's a long story why I need this instead of the other version, but I am sure this is the only way to fix my problem
Jul 06, 2010 @ 14:06
I have seen this fix a number of places but need the reverse fix.Does anyone know how to code the .htaccess to force /index.html to show?
I figure I can set a different default file with an embedded redirect to /index.html but would like this to be handled at .htaccess level
It's a long story why I need this instead of the other version, but I am sure this is the only way to fix my problem
vincent Said,
RewriteEngine On
RewriteBase /
RewriteRule ^$ http://www.domain.com/index.html [R=301,L]
Jul 06, 2010 @ 14:44
The reverse can be done using:RewriteEngine On
RewriteBase /
RewriteRule ^$ http://www.domain.com/index.html [R=301,L]
vince Said,
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.your_domain.com$
RewriteRule ^(.*)$ http://www.your_domain.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.your_domain.com/ [R=301,L]
Jul 06, 2010 @ 14:48
@Vacation RentalsRewriteEngine on
RewriteCond %{HTTP_HOST} !^www.your_domain.com$
RewriteRule ^(.*)$ http://www.your_domain.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.your_domain.com/ [R=301,L]
don tata Said,
Jul 25, 2010 @ 18:13
Excellent guide, been looking for this for a week because google indexed my site as site.com/index.html instead of site.com I also want to thanks Vince for posting the combined code.
rod Said,
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.your_domain.com/$1 [R=301,L]
Sep 30, 2010 @ 01:45
If you want a shorter method mention by vince try my method which i was experimented and learn from others.RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.your_domain.com/$1 [R=301,L]
Louise Said,
Thanks
Oct 14, 2010 @ 07:38
Hi, let me know what need to do for fix problem with slash of the end query string for html page. For exampl. site.com/h.html/ need 301 redirect to site.com/h.htmlThanks
Lora Said,
Example: http://mysite.com/ and the other
http://www.mysite.com/, how to avoid the slash and use only one index.Thank you in advance, any help would be really appreciated.
Oct 04, 2011 @ 23:19
I need a bit of help in here. I have 2 index.html on my site, and both end with a slashExample: http://mysite.com/ and the other
http://www.mysite.com/, how to avoid the slash and use only one index.Thank you in advance, any help would be really appreciated.
magician london Said,
May 04, 2012 @ 18:07
Ah thank you for such a great article this has really helped! | Previous: Force www vs non-www to avoid duplicate content on Google | Next: How to block users from accessing your site based on their IP address |

Would you mind emailing me if you update this?
Craig