Explanation of the Issue (URL canonicalization):
When both the “www” and “non-www” versions of our website are accessible, search engines like Google might treat them as two separate websites. This can lead to several issues:
- Duplicate Content: Search engines may see www.example.com and example.com as different websites with the same content, resulting in duplicate content issues. This can split the ranking signals between the two versions and dilute the effectiveness of our SEO efforts.
- Link Equity Dilution: Backlinks to our site could be split between www.example.com and example.com. This division reduces the overall link equity because the authority and ranking power of our links are spread across two domains.
- Crawl Budget Wastage: Search engines allocate a specific crawl budget for each website. If both versions are crawled, this budget is wasted, potentially leading to less frequent crawling of important pages on our site.
Example Scenario:
Current State:
- http://example.com/page and http://www.example.com/page both exist and can be accessed.
- Search engines crawl and index both URLs.
- Backlinks are split between example.com and www.example.com.
- Duplicate content issues arise.
After Resolution:
- http://example.com/page redirects to http://www.example.com/page via a 301 redirect.
- Only http://www.example.com/page is indexed by search engines.
- All internal links on our website point to www.example.com URLs.
- External backlinks are updated to www.example.com where possible.
- Canonical tags on all pages point to www.example.com.
- The XML sitemap lists only www.example.com URLs.
- All resources are served over HTTPS from www.example.com.
Similar to:
https://facebook.com/ leads to https://www.facebook.com/
https://google.com/ leads to https://www.google.com/
Solution Steps:
To resolve this issue, we need to ensure that only the preferred version (www.example.com) is indexed and accessible by search engines. Here’s how we can do this:
1. Choose Our Preferred Domain
In this case, the preferred domain is www.example.com.
2. Set Up 301 Redirects
Implement 301 redirects from the non-preferred version (example.com) to the preferred version (www.example.com). This tells search engines that the content has permanently moved. Here’s how we can set it up for different web servers:
Example For Apache (.htaccess):
apache
Copy code
# Redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^index\.dev [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
For Nginx:
nginx
Copy code
# Redirect non-www to www
server {
listen 80;
server_name example.com;
return 301 http://www.example.com$request_uri;
}
3. Update Internal Links
Ensure all internal links within our site point to the preferred version. For example, update any links from example.com/page to www.example.com/page.
4. Use Canonical Tags
Add canonical tags to our pages to indicate the preferred version to search engines. For example, on a page located at example.com/page, add the following HTML tag within the <head> section:
html
Copy code
<link rel=”canonical” href=”http://www.example.com/page” />
5. Update Our Sitemap
Ensure our XML sitemap lists only the URLs of the preferred version (www.example.com). Submit the updated sitemap to Google Search Console.
6. Check for Mixed Content Issues
If we are using HTTPS, make sure all resources (images, scripts, CSS files) are loaded over HTTPS and point to the preferred domain. For example:
html
Copy code
<!– Correct –>
<img src=”https://www.example.com/image.jpg” alt=”Example Image”>
<!– Incorrect –>
<img src=”http://example.com/image.jpg” alt=”Example Image”>
By implementing these steps, we can make sure that search engines and users are directed to our preferred version of the site, consolidating our SEO efforts and improving our site’s search engine ranking.