Ratings, reviews, plans and features to help you find the right web hosting provider for your site.

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).


  1. How to block users from accessing your site based on their IP address
  2. How to prevent or allow directory listing?
  3. How to change the error documents – 404 Page Not Found, etc
  4. Using .htaccess for password protecting your folders
  5. Using .htaccess to block referrer spam
  6. Disable Hot-Linking of images and other files
  7. Redirect URLs using .htaccess
  8. Introduction to mod_rewrite and some basic examples
  9. Force SSL/https using .htaccess and mod_rewrite
  10. 301 Permanent redirects for parked domain names
  11. Enable CGI, SSI with .htaccess
  12. How to add Mime-Types using .htaccess
  13. Change default directory page
  14. Block Bad robots, spiders, crawlers and harvesters
  15. Make PHP to work in your HTML files with .htacess
  16. Change PHP variables using .htaccess
  17. HTTP Authentication with PHP running as CGI/SuExec
  18. Force www vs non-www to avoid duplicate content on Google
  19. Duplicate content fix index.html vs / (slash only)

Comments 13 >>

Vacation Rentals Said,
Mar 06, 2008 @ 23:44

I see a lot of people telling how to do this fix & then also the www vs non www workaround, but not many people show how to combine both. Could you show an example of the htaccess file with both rules combined?

Would you mind emailing me if you update this?

Craig
Art Village Said,
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,
RSQ Said,
Jul 20, 2009 @ 10:53

gr8 article its working
thanks
Wedding Magician - Roger Lapin Said,
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,
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,
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,
Jul 06, 2010 @ 14:48

@Vacation Rentals

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]
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,
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,
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.html

Thanks
Lora Said,
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 slash
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.
Kim Said,
Feb 06, 2012 @ 21:05

Sorry,
Just read it above.
Thanks
magician london Said,
May 04, 2012 @ 18:07

Ah thank you for such a great article this has really helped!
Your comments on this article

(required)

(required but never displayed)



security code



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