1

I'm getting the following critical error when running my website through Site Checker.

Search engines see your https://www.example.com and https://www.example.com/index.html (or https://www.example.com/index.php) as different pages.

If you don't explicitly tell Google which URL is canonical, Google will make the choice for you or might consider them both of equal weight, which might lead to unwanted behavior.

I can understand what it is telling me and I've spent many hours researching to find a fix but with no luck. I've read Googles article (and watched the video) but this didn't give me any clues. I'd already done the redirects due to another warning site checker previously gave me.

I've added the tag rel="canonical" unfortunately this did not resolve the issue.

I have the following in my .htaccess file as suggested in another post.

# Force HTTPS and WWW 
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [OR,NC]
RewriteCond %{https} off  
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]


Redirect 301 /index.html https://www.example.com/index.php
Redirect 301 /default.php https://www.example.com/index.php
DirectoryIndex index.php
MrWhite
  • 43,179
  • 8
  • 60
  • 84
Taggs74
  • 11
  • 2
  • Does this answer your question? [Apache .htaccess to redirect index.html to root, why FollowSymlinks and RewriteBase?](https://stackoverflow.com/questions/3771175/apache-htaccess-to-redirect-index-html-to-root-why-followsymlinks-and-rewriteb) – Stephen Ostermiller Apr 06 '22 at 17:34
  • What is your canonical URL(s)? What URL are you using in your internal links? Your "redirects" would appear to suggest that having `/index.php` in the URL is canonical? But that isn't generally desirable. (?) – MrWhite Apr 07 '22 at 01:38
  • 1
    my internal links are all https://www.mywebsite.co.uk/whateverpage.php and my canonical URL is https://www.mywebsite.co.uk/index.php @MrWhite – Taggs74 Apr 07 '22 at 19:09
  • @StephenOstermiller unfortunately not, but thanks anyway. – Taggs74 Apr 07 '22 at 19:10
  • 1
    Your canonical URL should NEVER include `index.php` (or `index.html`). The canonical URL should be just `https://mywebsite.co.uk/` for the home page. – Stephen Ostermiller Apr 07 '22 at 19:31

1 Answers1

1

If your canonical URL is example.com/index.php (as opposed to simply example.com/ - which is generally preferred*1) then...

  • Make sure you are linking to /index.php throughout your site (not simply /).

  • Set the rel="canonical" tag to your canonical URL (ie. https://www.example.com/index.php). This should be enough to resolve the canonicalization issue that "Site Checker" is reporting, despite what it states.

  • Create the following redirect at the top of the .htaccess file in the document root to redirect from / to /index.php.

    # Canonical redirect
    RewriteRule ^$ https://www.example.com/index.php [R=301,L]
    

    (Test first with a 302 - temporary - redirect.)

Redirect 301 /index.html https://www.example.com/index.php
Redirect 301 /default.php https://www.example.com/index.php

Unless you previously had a index.html (or default.php) file that served your homepage content then these redirects are not required. (You should be using RewriteRule instead anyway - as above). Presumably requests for index.html or default.php return a "404 Not Found"?


*1 example.com/ should be canonical, not example.com/index.php

Consider setting the canonical URL to example.com/ instead of example.com/index.php. Using example.com/ is generally expected, looks better, shorter. The /index.php part of the URL carries no SEO benefit. It is not necessary to include the DirectoryIndex in the URL-path.

For this, the process is the same as above, just the other way round. And the canonical redirect would be of the form:

# Canonical redirect from "/index.php" to "/"
RewriteRule ^index\.php$ https://www.example.com/ [R=301,L]
MrWhite
  • 43,179
  • 8
  • 60
  • 84