Sub topic 3
Implementing Canonicals: Link Elements, HTTP Headers, and Sitemaps
Assume you understand HTML head elements, URL query strings, and HTTP status codes. A canonical URL is the preferred URL for a page when several URLs show the same or nearly the same content.
Implementing Canonicals
For HTML pages, add an absolute canonical URL in the head:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Trail Running Shoes | Example Store</title>
<link rel="canonical" href="https://www.example.com/shoes/trail-running">
</head>
<body>
<h1>Trail Running Shoes</h1>
</body>
</html>A PDF or another non-HTML response can use an HTTP Link header:
HTTP/1.1 200 OK
Content-Type: application/pdf
Link: <https://www.example.com/guides/size-guide>; rel="canonical"Sitemaps also communicate preferred URLs. Include the canonical URL, not tracking or temporary variants:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.example.com/shoes/trail-running</loc>
</url>
</urlset>Choosing the Canonical URL
Choose the version that is stable, accessible, indexable, and representative of the content. Usually this means HTTPS, one preferred hostname, and a clean path without tracking parameters.
Canonical, Redirects, Noindex, and Robots.txt
- Use
rel="canonical"when duplicate URLs must remain available. - Use a
301redirect when the old URL should permanently send users elsewhere. - Use
noindexwhen a page may be visited but should not enter the search index. - Use
robots.txtto control crawling, not to select an indexed duplicate. A blocked page may prevent search engines from seeing its canonical hint.
Common Mistakes and Templates
Common failures include relative URLs, HTTP canonicals on HTTPS pages, canonicalizing every page to the homepage, and conflicting HTML, header, and sitemap signals.
Generate tags from one normalized URL function in your template framework. Preserve parameters that change the content, and remove tracking parameters. Each page should render one canonical link.
Auditing and Monitoring
Crawl the site and check for:
- Missing, duplicate, or non-absolute canonicals
- Canonicals that return errors or redirect
- Canonicals that disagree with sitemaps
- Pages whose canonical target has different content
- Unexpected title or description changes
Exercise
A product page is available at /shoe, /shoe?utm_source=email, and /shoe?color=red. Which URL should usually be canonical?
Show answer
Use /shoe for tracking-only duplication. Use /shoe?color=red as a separate canonical only if the color page has distinct, indexable content.