Sometimes, due to inconsistent linking, a link my be made to your homepage as / or it may be linked as /index.php
Usually, both these pages are the same thing as index.php is usually configured in Apache as the page to be displayed when a directory is requested. In this tutorial, we will look at redirecting the index page to the directory root in Apache to prevent duplicate content issues.
Some search engines are smart enough not to penalize you for these kinds of duplicate pages. However, all search engines should recognize them as duplicate pages, and rightfully so, as they are indeed more than one page (different URLs) with the same content. They should have no regard to whether one may be the directory index or not.
The example below assumes you are redirecting http://www.example.com/index.php to http://www.example.com
All you have to do to solve this problem is add the following lines to a/the .htaccess file in your document root:
# ensure that there is one of these lines in your .htaccess RewriteEngine on # ensures that the appropriate conditions are met RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ # redirect (using a 301 response header) if match is found RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
What we do is first match the condition that we want. In this case we are looking for /index.php in the HTTP request, which would indicate that someone is attempting to request index.php from the web root. We then issue the appropriate 301 redirect to get them to the directory root of the website instead. This boils down to the same page but the URL will not have index.php in it.
We hope this tutorial was helpful and that it aids you in preventing duplicate content in the search engines.