Avoid duplicate content from index.html or index.php

Todays SEO post is a quick and easy one to avoid duplicate content.

http://www.craigharris.org
http://www.craigharris.org/index.php

Both this links return the same page and would be considered duplicate content by Google. To fix this include the following bit of code in your sites .htaccess file:

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

If your site uses a .HTML main page use this:

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]

This will redirect all requests for the index page to the directory root avoiding duplication. If you have more RewriteRule lines in your .htaccess file you can remove the L at the end.

Read my previous article on duplicate content with the WWW sub-domain here: http://www.craigharris.org/2011/03/18/to-www-or-not-to-www-that-is-the-duplicate-content-question/

This entry was posted in Servers, Websites and tagged , , , , . Bookmark the permalink.

2 Responses to Avoid duplicate content from index.html or index.php

  1. Edgeless MMA says:

    Have just tried similar code from 5 different blogs and they didn’t work, this one did, thanks :)

  2. Dijitul says:

    This works perfectly. For anyone that uses Cubecart for their online shop this code sorts out the problem straight away.

    Good work Craig, thanks :-)

Leave a Reply

Your email address will not be published. Required fields are marked *


(required)*