Jump to content
KUHM

Avoiding Duplicate Content on the Homepage: index.php, index.html and /accueil

Posted on - Updated

Avoiding Duplicate Content on the Homepage: index.php, index.html and /accueil

I often detect duplicate content issues on a site's homepage: the same page responds at several different addresses, and each variant (index.php, index.html, /accueil) can be crawled by search engines as a separate page.

Why index.php creates duplicate content on the homepage

The Apache server serves a default file when the address ends with a slash: this is the DirectoryIndex directive, which most often points to index.php or index.html. The site root and the file itself therefore display exactly the same content. As long as nobody links to index.php, the problem stays theoretical; it becomes real as soon as a menu, a clickable logo, a CMS or a partner site points to the long version of the address.

The variants I come across most often:

  • / (the root, the address to keep);
  • /index.php;
  • /index.html and /index.htm;
  • /accueil or /home, created by some CMSs;
  • the same addresses with and without www, or in http and https.

For a search engine, each of these URLs is a separate document. It has to choose which one to show, and the links received by the homepage are spread across several addresses instead of being concentrated on one.

What Google does with duplicate URLs

Google groups identical pages and picks a canonical URL, the one it judges representative of the group. Its Search Central documentation presents the permanent redirect as a strong signal for this choice, the rel="canonical" tag as a weaker signal and the sitemap as a mere hint. Without any instruction from you, the engine may pick index.php as the official address of your homepage, which is never the goal. Internal duplicate content does not lead to a penalty when there is nothing deceptive about it, but it dilutes the page's popularity and keeps the crawler busy with duplicates.

The fixed htaccess code to redirect index.php to the root

The rule originally published in this article, RewriteRule ^index.php$ [QSA,L,R=301], does not work: it lacks the destination address. A rule written too simply can also loop, because Apache itself rewrites the root to index.php internally. The following version only redirects the addresses actually requested by the browser:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(.*/)?index\.(php|html?)[\s?] [NC]
RewriteRule ^(.*/)?index\.(php|html?)$ /$1 [R=301,L]

The condition reads the request line sent by the browser (THE_REQUEST), and not the address rewritten by the server: the loop disappears. The pattern covers index.php, index.html and index.htm, at the root as in subfolders (/blog/index.php redirects to /blog/). Any parameters in the address follow the redirect. The 301 code announces a permanent move: it is what passes the signals from the old address to the new one.

Redirecting /accueil and /home to the root

The /accueil or /home pages created by a CMS are handled with one more rule, placed below the previous ones:

RewriteRule ^(accueil|home)/?$ / [R=301,L,NC]

Then check that the CMS no longer produces these addresses in its menus and logo: a redirect repairs, a clean link avoids the problem at the source.

Check that the redirect works

Three checks are enough once the .htaccess file is online:

  1. type the index.php address in the browser: the address bar should show the root;
  2. check the response code in the Network tab of the developer tools: a single 301 redirect, then the normal homepage, with no intermediate step;
  3. in Search Console, inspect the index.php URL a few weeks later: Google should report it as a page with a redirect.

A server error right after uploading the file most often signals a missing mod_rewrite module or a typo: put the old .htaccess back, then fix the rule before uploading it again.

The canonical tag as a complement to the redirect

When a redirect is impossible (hosting without mod_rewrite, a CMS that imposes its addresses), the tag <link rel="canonical" href="https://www.exemple.fr/"> placed in the homepage header tells the engine which address to keep. It does not replace the redirect: the visitor stays on the duplicate address, and Google treats it as a hint that it can ignore. The two combine well, and the canonical also protects against duplicates created by tracking parameters added to campaign links (utm_source and its neighbors).

A site without technical duplicates leaves all the room for editorial work: writing web content designed for SEO loses part of its effect if the homepage is split across three addresses. The same logic applies to anyone who wants to create quality web content: one URL per piece of content, always.

And you, do you find this kind of redirect useful?

About the author

Cyril KUHM

Cyril KUHM

Head of MKH, a web agency near Strasbourg, and SEO consultant since 2007. On this blog I share free, hands-on advice to help your site rank better on Google.

Get in touch

Related posts

↑