Canonical URLs
Introduction
A canonical URL (rel="canonical") is an HTML link tag that tells search engines which version of a URL you want to appear in search results. It solves duplicate content issues.
Why it matters
If your site can be accessed via multiple URLs (e.g., http://example.com, https://example.com, https://www.example.com, or with tracking parameters like ?utm_source=twitter), search engines might index them as separate pages. A canonical tag consolidates these into one master URL.
Where it appears
- Invisible to users, located in the
<head>of your HTML document. - Search Engine Indexes (Google, Bing).
Requirements
- A valid, absolute URL inside a
<link rel="canonical">tag.
Best Practices
- Always use absolute URLs (e.g.,
https://example.com/page), not relative paths (/page). - Self-referential canonical tags are good practice (a page pointing to itself).
- Ensure the canonical URL returns a 200 OK status.
Common Mistakes
- Pointing a canonical tag to a 404 page or a redirect.
- Using relative URLs.
- Having multiple canonical tags on the same page.
Implementation
<head>
<!-- Other meta tags -->
<link rel="canonical" href="https://www.example.com/learn/canonical" />
</head>