'Consolidate duplicate URLs
I'm getting the following critical error when running my website through Site Checker.
Search engines see your
https://www.example.comandhttps://www.example.com/index.html(orhttps://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
Solution 1:[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.phpthroughout 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
.htaccessfile 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"?
*1example.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]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
