For AI agents: the complete documentation index is available at https://nhanbe.id.vn/llms.txt, the full documentation bundle is available at https://nhanbe.id.vn/llms-full.txt, and this page is available as Markdown at https://nhanbe.id.vn/building-for-the-web/web-seo/canonical-url-seo.md.

Canonical URL Guide

Canonical URLs and rel="canonical" tags: how canonicalization works, implementation methods, best practices, common mistakes, and auditing via Google Search Console.

Canonical URL Guide

What Is a Canonical URL?

Canonical URL: https://example.com/blog/
Duplicate URL: https://example.com/blog/?page=1
  • A canonical URL is the preferred version of a webpage that search engines index and show in search results when multiple URLs load the same or very similar content.
  • Canonicalization is the process of selecting one representative URL from a set of duplicate or near-duplicate URLs to consolidate ranking signals.
  • Google determines the canonical URL using multiple signals: protocol (HTTPS vs. HTTP), 3xx redirects, rel="canonical" tags, and URLs listed in Sitemap.xml.
[Canonical as a strong hint]

rel="canonical" is a strong hint, not an absolute directive. When site signals conflict or another URL better serves searchers, Google may select a different canonical URL than the declared one.

Common Causes of Duplicate URLs

  • Protocol variants: both http:// and https:// versions remain accessible.
  • Domain variants: both www and non-www hostnames resolve to the same content.
  • Trailing slash differences: URLs with and without a trailing / (e.g., /page vs. /page/).
  • URL parameters: tracking, sorting, or filtering query strings (e.g., ?utm_source=email, ?sort=price).
  • Session IDs: temporary identifiers appended to URLs per user session.
  • Device-specific URLs: separate mobile URLs such as m.example.com and example.com.
  • Pagination: paginated pages with highly similar content (e.g., /blog vs. /blog?page=1).

What Is a Canonical Tag (rel="canonical")?

index.html
<head>
  <link rel="canonical" href="https://example.com/products/blue" />
</head>
  • A <link rel="canonical" ... /> element belongs inside <head> on both duplicate URLs (e.g., https://example.com/product/blue?sort=price) and the main URL to point search engines to the preferred version.
  • Self-referencing canonical: every canonical page should include a rel="canonical" tag pointing to its own URL, even without obvious duplicates, to keep signals consistent.

Why Canonical Tags Matter

  • Control SERP URLs: keeps alternate URLs out of search results and prevents keyword cannibalization.
  • Consolidate link equity: directs backlink authority from duplicate variations to a single preferred URL.
  • Simplify analytics and reporting: consolidates performance metrics, keywords, and conversions to one URL.
  • Reduce wasted crawl budget: helps crawlers prioritize primary URLs on large sites.
[Syndicated content]

Google no longer recommends using rel="canonical" for syndicated content. Syndication partners should block indexing with Robots.txt or a noindex meta tag instead.

Other Ways to Specify Canonical URLs

No — retire old URLs or mergeHTTPYes — keep both URLsYesNo (PDF, DOCX...)Duplicate URLs existKeep alternateURLs accessible?Use 301 RedirectIs the resourcean HTML page?Add rel='canonical'in <head>Send rel='canonical'HTTP HeaderInclude only canonicalURLs in Sitemap
MethodWhen to UseLimitations
rel="canonical" tagDuplicate URLs exist and must remain accessibleDoes not work for non-HTML files
3xx Redirect (301)Retiring old URLs, merging domains, or enforcing HTTPSAlternate URLs are no longer directly accessible
rel="canonical" HTTP HeaderNon-HTML files (PDF, DOCX) or no HTML accessRequires server/CDN config access
XML SitemapReinforcing canonical signals alongside other methodsNot sufficient as a standalone method

1. Redirects

Use server-side 301 redirects when alternate versions do not need to stay accessible—for example, redirecting http:// to https:// or consolidating retired URLs.

2. rel="canonical" HTTP Headers

.htaccess
Header add Link: <https://www.example.com/downloads/filename.pdf>; rel="canonical"
  • Used for non-HTML documents (such as PDF or DOCX files) where an HTML <head> tag cannot be added.
  • Requires server configuration access (.htaccess, Nginx, or application response headers).

3. XML Sitemaps

  • Submit only canonical URLs in Sitemap.xml.
  • Exclude parameterized URLs, paginated pages (/page/2, /page/3), and HTTP variants when HTTPS is canonical.

CMS Quick Reference

  • WordPress: use Yoast SEO or Rank Math SEO; set the Canonical URL under the Advanced tab in the editor (leaving it blank generates a self-referencing canonical by default).
  • Shopify: automatically adds canonical tags to products, collections, and blog posts; custom rules require editing theme.liquid with metafields or using a dedicated app.
  • Magento 2: enable Use Canonical Meta Tags For Categories and Products under Stores > Settings > Configuration > Catalog > Catalog > Search Engine Optimization.
  • Wix: generates self-referencing canonicals site-wide by default; overrides are available per page type or under SEO Basics > Advanced SEO > Additional Tags.

Canonical Tag Best Practices

Valid vs. Invalid
<!-- ✅ Absolute URL, HTTPS, consistent trailing slash -->
<link rel="canonical" href="https://example.com/blog/" />

<!-- ❌ Relative URL -->
<link rel="canonical" href="/blog/" />

<!-- ❌ HTTP protocol on an HTTPS site -->
<link rel="canonical" href="http://example.com/blog/" />
  • Use self-referencing canonicals on every indexable page, even when no duplicates exist.
  • Specify one canonical URL per page: multiple canonical tags or conflicting HTML + HTTP-header canonicals may cause search engines to ignore all of them.
  • Match the site protocol: use https:// across all canonical URLs on an HTTPS site.
  • Stay consistent on trailing slashes and www / non-www: align internal links, redirects, sitemaps, and canonicals to the same format.
  • Always use absolute URLs: include the full protocol and domain.

Common Mistakes to Avoid

1. Pointing Canonicals to Redirected Pages

If Page A redirects to Page B, canonical tags must point directly to Page B. Pointing a canonical to Page A sends conflicting signals ("prefer this page" vs. "this page moved").

2. Using Canonicals for Non-Duplicate Content

Canonical tags only apply to identical or near-identical content. Distinct items (such as two different headphone models) should each carry a self-referencing canonical so both remain eligible to rank.

3. Placing Canonical Tags Outside <head>

Search engines may ignore rel="canonical" tags placed in <body> or outside <head>. Verify placement via View page source.

4. Conflicting Canonical and hreflang Tags

https://example.com/es/tema
<head>
  <!-- ✅ Each language version self-canonicals and lists all hreflang alternates -->
  <link rel="canonical" href="https://example.com/es/tema" />
  <link rel="alternate" hreflang="en" href="https://example.com/topic" />
  <link rel="alternate" hreflang="es" href="https://example.com/es/tema" />
  <link rel="alternate" hreflang="fr" href="https://example.com/fr/sujet" />
</head>
  • rel="canonical" indicates the preferred page version, whereas hreflang maps language/region equivalents.
  • Pointing all language versions to a single canonical (e.g., /topic) conflicts with hreflang. Each localized page should self-canonical to its own URL while listing all hreflang alternates, including itself.

Auditing Canonical Tags

1. Google Search Console (URL Inspection)

  1. Open Google Search Console and inspect the target URL.
  2. Expand the Page indexing section.
  3. Compare User-declared canonical against Google-selected canonical.
  4. When they differ, audit all signals—canonical tags, redirects, internal links, and sitemaps—to ensure consistency.

2. Site-Wide Crawl

Run a site-wide crawl (such as Semrush Site Audit, filtering the Issues tab by canonical) to catch:

  • Pages with duplicate content issues.
  • Pages with multiple canonical URLs.
  • Broken canonical links (404 or redirect chains).
  • AMP pages missing canonical tags.

References