getButterfly Logo getButterfly

If you are receiving warnings or even errors about your homepage being accessible both via domain.ext and domain.ext/index.php, there are two solutions:

Add to your header file, or to your index.php file the following snippet:

$cpage = $_SERVER[‘REQUEST_URI’];
if($cpage == ‘/’ || $cpage == ‘/index.php’)
echo ‘<link rel=”canonical” href=”” />’;

This way, Google (and the other search engines out there) will consider both your root domain and your specified search page as one canonical URL link.

The second solution is using .htaccess (if available) to redirect index.php to root, like this:

[code]Options +FollowSymLinks
DirectoryIndex index.php

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L][/code]

Subscribe to getButterfly Blog

Once a week or so we send an email with our best content. We never bug you, we just send you our latest piece of content.

If you found any value in this post, agree, disagree, or have anything to add - please do. I use comments as my #1 signal for what to write about. Read our comment policy before commenting! Comments such as "Thank you!", "Awesome!", "You're the man!" are either marked as spam or stripped from URL.

Leave a Reply

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