Technical SEO
Canonical tags: when to use them, how to add them, and the mistakes that get them ignored
Use canonical tags when the same content must stay reachable at more than one URL, such as tracking parameters or sort orders, and use a 301 redirect when the duplicate URL is not needed. Put one absolute rel="canonical" link in the head, pointing to a page that returns 200 and is indexable. Google treats it as a strong signal, not a command, so your links, sitemap and redirects must agree with it.
What does a canonical tag actually do?
A canonical tag is one line in the <head> of a page that names the URL you want search engines to treat as the main version of that content:
<link rel="canonical" href="https://www.example.com/shoes/red-sneakers/">
Most sites serve the same page at more than one address without meaning to. /shoes/red-sneakers/, /shoes/red-sneakers, /shoes/red-sneakers/?utm_source=newsletter and the http:// version can all return the same HTML. Google groups those duplicates together, picks one to show in results, and treats the rest as alternates. The canonical tag is how you tell it which one you prefer.
It is a preference, not a command. Google's guide to consolidating duplicate URLs calls rel="canonical" "a strong signal that the specified URL should become canonical," and its troubleshooting page says Google "might choose a different canonical for various reasons, such as the quality of the content or technical signals." So the tag works best when every other signal on the site agrees with it: your internal links, your sitemap and your redirects.
Duplicate URLs are a normal part of the web, and Google notes that you do not have to declare a canonical at all; your site "will likely do just fine" without one. You set it to get control over which URL shows in results, to combine link signals onto one URL, to keep analytics for one page in one place, and so Googlebot spends its crawl time on pages that are actually different.
When should you use a canonical tag, and when should you redirect instead?
Google lists three ways to state a canonical preference, ranked "in order of how strongly they can influence canonicalization." Pick by one question: does anyone still need to reach the duplicate URL?
| Method | Google's description of its strength | Use it when |
|---|---|---|
| Permanent redirect (301 or 308) | "A strong signal that the target of the redirect should become canonical" | Nobody needs the old URL: http to https, www to non www, a page that moved, a trailing slash variant. |
rel="canonical" link or HTTP header | "A strong signal that the specified URL should become canonical" | Both URLs must keep working: tracking parameters, sort orders, print versions, a product reachable under two categories, the same article syndicated to your other site. |
| Listing the URL in your XML sitemap | "A weak signal" | Always, as support for the other two. List only canonical URLs. |
Source: Google Search Central, How to specify a canonical URL (checked November 2026). Google adds that the methods "can stack and thus become more effective when combined," which is the practical rule: redirect what you can, canonicalize what you cannot, and make the sitemap and internal links match.
A common mix up is using a canonical where a redirect belongs. If http://example.com/about still returns a 200 with a canonical pointing at the https page, visitors and other sites keep landing on the http version, and Google has to keep crawling both. Host, protocol and trailing slash variants should be redirects at the server or host level. Our guide to redirect chains covers how to set those up on Netlify and Vercel without stacking hops.
How do you add a canonical tag correctly?
Follow these steps in order. Each one matches a rule in Google's documentation.
- Decide the one URL format for the whole site. Protocol (https), host (www or not) and trailing slash (on or off). Write it down. Every canonical, internal link and sitemap entry uses that format.
- Put the tag inside
<head>. Google says the element "is only accepted if it appears in the <head> section of the HTML." A canonical that lands in<body>, often because a script or invalid markup closed the head early, is ignored. - Use an absolute URL. Google's guidance is to "use absolute paths rather than relative paths." Write
https://www.example.com/dresses/green/, not/dresses/green/. - Add a self referencing canonical on canonical pages. Google recommends including a canonical on the canonical page itself. Then any parameter version of that page, such as a link with
?ref=twitter, already points back to the clean URL. - Output exactly one canonical per page. Two different canonicals (a theme and an SEO plugin each adding one is the classic cause) is a contradiction, and Google has to guess which one you meant.
- Point it at a page that returns 200 and is indexable. Not a redirect, not a 404, not a page with
noindex, and not a URL with a#fragment, which Google says not to use as a canonical. - Link internally to the canonical version. Google says to link to the canonical URL rather than a duplicate. Your nav, breadcrumbs and in content links are a vote.
- Put it in the HTML your server sends. Google asks you to set the canonical in the HTML source and to make sure JavaScript does not change it. If your framework only renders it client side, fix that in the server render or the static build.
In most frameworks this is one setting. Next.js has alternates.canonical in its metadata API, Astro and Eleventy sites usually build it from a site URL plus the page path, and WordPress SEO plugins add it automatically. Whatever builds it, check the output, not the config.
What are the most common canonical tag mistakes?
These are the problems that show up again and again when you crawl small sites. Each one either gets the tag ignored or tells Google something you did not mean.
| Mistake | What happens | Fix |
|---|---|---|
| Every page canonicalizes to the home page | You are asking Google to treat every page as a duplicate of the home page. Usually a template bug. | Build the canonical from the current page path, not a fixed site URL. |
Relative URL (a path like /about instead of a full URL) | Easy to resolve wrongly on staging, http or alternate hosts. | Use the full absolute URL. |
Canonical in <body> | Ignored, because Google only accepts it in the head. | Move it up; check for elements that end the head early. |
| Two or more different canonicals | Conflicting signals; Google has to guess. | Remove the duplicate output (theme or plugin). |
| Canonical points to a redirect or a 404 | You nominate a URL that is not a page. | Point it at the final 200 URL. |
| Canonical chain (A points to B, B points to C) | Google has to guess where you meant. | Point every duplicate straight at the final URL. |
noindex plus a canonical to another page | Two different instructions on one page. | Pick one. Google says it does not recommend noindex for choosing a canonical within a site. |
| http canonical on an https site | Contradicts your redirects; Google generally prefers HTTPS. | Use the https URL everywhere. |
| Paginated pages all point to page 1 | Pages 2 and up, and the items only linked from them, can drop out. | Each page canonicalizes to itself (see below). |
| Robots.txt blocks the duplicate | Google cannot crawl it to see the canonical tag at all. | Unblock it and let the canonical do its job. |
Source: Google Search Central consolidation and troubleshooting guides, checked November 2026. Two of Google's flat rules from that guide are worth repeating because people reach for these tools under pressure: "Don't use the robots.txt file for canonicalization purposes," and "Don't use the URL removal tool for canonicalization. It hides all versions of a URL from Search."
The last mistake on the list is subtle. Google also says not to specify different URLs as canonical for the same page "using different canonicalization techniques." If your sitemap lists /page while the tag says /page/ and the server redirects to /page/, you have sent three signals, two of them in agreement. Make all three match.
How should paginated pages and filtered listings handle canonicals?
This is where older advice is now wrong. Google's pagination guide says: "Don't use the first page of a paginated sequence as the canonical page. Instead, give each page its own canonical URL." So /blog/page/2/ canonicalizes to /blog/page/2/, not to /blog/.
The same guide says Google no longer uses rel="next" and rel="prev", although other search engines may. What Google does use is normal <a href> links between pages in the sequence, and it suggests linking every page in the series back to the first page as a hint that page 1 is the better landing page. Give each page a real URL such as ?page=2; a #page=2 fragment is not a separate URL to Google.
Filters and sort orders are different. /shoes/?sort=price shows the same items as /shoes/ in a different order, so a canonical to /shoes/ fits. For filter combinations you never want indexed, the same Google guide suggests noindex or robots.txt rules. Choose per pattern, and do not apply both a robots.txt block and a canonical to the same URLs, since a blocked page cannot be crawled to read the tag.
How do you set a canonical for PDFs and other non HTML files?
A PDF has no <head>, so Google supports the same signal as an HTTP response header, for web search results only. Use it when, for example, the same white paper exists as a PDF and as an HTML page, and you want the HTML page to rank. The header looks like this:
Link: <https://www.example.com/white-paper/>; rel="canonical"
On Netlify, add it in a _headers file in your publish directory, following the format in the Netlify custom headers docs: the path on one line, each header indented below it.
/downloads/white-paper.pdf
Link: <https://www.example.com/white-paper/>; rel="canonical"
On Vercel, use the headers property in vercel.json, as described in the vercel.json docs:
{
"headers": [
{
"source": "/downloads/white-paper.pdf",
"headers": [
{
"key": "Link",
"value": "<https://www.example.com/white-paper/>; rel=\"canonical\""
}
]
}
]
}
After deploying, confirm the header is really there with curl -sI https://www.example.com/downloads/white-paper.pdf | grep -i '^link:'. No output means the rule did not match the path. If you only have the PDF and no HTML version, you do not need a canonical for it.
How do you check every canonical on your site?
For one page, view the raw HTML rather than the browser's inspected DOM, so you see what crawlers get first:
curl -s https://www.example.com/pricing/ | grep -io '<link[^>]*rel="canonical"[^>]*>'
Two lines of output means two canonicals. No output means none in the HTML (or one added later by JavaScript, which is its own problem).
For a whole site, run the checks in bulk. This standard library Python script reads a list of URLs, finds the canonical in the head, and flags each mistake from the table above: missing, in the body, more than one, relative, http on https, a fragment, noindex with a cross page canonical, and a target that redirects, 404s, is noindex or canonicalizes again. It does not follow redirects, so it reports the status the target really returns. We ran it against a local test server with one page per mistake, and each case was flagged.
#!/usr/bin/env python3
"""Check the rel=canonical on each URL for the common mistakes."""
import sys, urllib.request, urllib.error
from html.parser import HTMLParser
from urllib.parse import urljoin
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *args, **kwargs):
return None
opener = urllib.request.build_opener(NoRedirect)
class Head(HTMLParser):
def __init__(self):
super().__init__()
self.in_head, self.canon, self.body_canon, self.noindex = True, [], [], False
def handle_starttag(self, tag, attrs):
a = {k: (v or "") for k, v in attrs}
if tag == "body":
self.in_head = False
if tag == "link" and "canonical" in a.get("rel", "").lower().split():
(self.canon if self.in_head else self.body_canon).append(a.get("href", ""))
if tag == "meta" and a.get("name", "").lower() == "robots" and "noindex" in a.get("content", "").lower():
self.noindex = True
def handle_endtag(self, tag):
if tag == "head":
self.in_head = False
def fetch(url):
req = urllib.request.Request(url, headers={"User-Agent": "canonical-check/1.0"})
try:
r = opener.open(req, timeout=15)
status, headers, body = r.status, r.headers, r.read().decode("utf-8", "replace")
except urllib.error.HTTPError as e:
status, headers, body = e.code, e.headers, ""
p = Head()
p.feed(body)
return status, headers, p
def check(url):
problems = []
status, headers, page = fetch(url)
if status != 200:
return [f"page itself returns {status}"]
if page.body_canon:
problems.append("canonical link is in <body>; Google ignores it there")
if not page.canon:
return problems + ["no canonical in <head>"]
if len(set(page.canon)) > 1:
problems.append(f"{len(page.canon)} different canonicals: {page.canon}")
href = page.canon[0]
if not href.startswith(("http://", "https://")):
problems.append(f"relative canonical {href!r}; use an absolute URL")
target = urljoin(url, href)
if url.startswith("https://") and target.startswith("http://"):
problems.append("canonical points to http:// on an https page")
if "#" in target:
problems.append("canonical contains a #fragment")
if page.noindex and target != url:
problems.append("noindex plus a canonical to another URL; pick one signal")
if target != url:
t_status, _, t_page = fetch(target)
if t_status != 200:
problems.append(f"canonical target returns {t_status}")
elif t_page.noindex:
problems.append("canonical target is noindex")
elif t_page.canon and urljoin(target, t_page.canon[0]) != target:
problems.append(f"chain: target canonicalizes again to {t_page.canon[0]}")
if not problems:
problems.append(f"note: points elsewhere, to {target} (fine if intended)")
return problems
if __name__ == "__main__":
urls = sys.argv[1:] or [l.strip() for l in sys.stdin if l.strip()]
for u in urls:
found = check(u)
label = "OK " if not found else "NOTE" if all(f.startswith("note:") for f in found) else "FIX "
print(label + " " + u)
for f in found:
print(" - " + f)
Save it as check_canonicals.py and feed it URLs, one per line. The simplest source is your own sitemap:
curl -s https://www.example.com/sitemap.xml | grep -o '<loc>[^<]*' | sed 's/<loc>//' | python3 check_canonicals.py
Lines marked FIX need attention. NOTE lines point somewhere other than themselves, which is fine for a parameter or print version and a bug on a normal page. One caution: every URL in your sitemap should come back OK, since your sitemap should list only canonical URLs.
If you work with an AI coding agent, this is a good task to hand over with the script output pasted in: "these pages canonicalize to the home page, find where the template builds the tag." Our walkthrough of a technical SEO audit with Claude Code shows how to structure that session. CrawlKind runs these canonical checks as part of a full crawl and lists each failing page with its evidence; you can see the format in the sample audit.
What if Google ignores your canonical?
Open the page in Search Console's URL Inspection tool, which shows the canonical you declared and the one Google selected. If they differ, Google's troubleshooting guide sets out the order to work through:
- Look for technical conflicts first. Run the checker above. Then compare the canonical with your redirects, sitemap entries, internal links and hreflang tags. Google's list of common causes includes CMS or plugin errors in the canonical element and misconfigured servers.
- Check whether the pages are actually different. If two pages are near copies, such as location pages that only swap the city name, Google may keep them clustered no matter what the tag says. Make each one clearly distinct, or merge them and redirect.
- Request indexing for the key URLs only. The Request Indexing button is quota limited, so use it for the handful of pages that matter.
- Wait two weeks before judging. Google says that even after fixes it "might hold pages in a duplicate cluster for up to two weeks," and that pages split out faster when the difference is "clear and significant."
A different Google selected canonical does not remove the content from Search. The cluster can still show in results, under the URL Google picked. It matters when the picked URL is the wrong one for users, such as a parameter URL or an old http address, or when it hides a page you wanted to rank on its own. For a broader pass that puts canonical fixes in order with everything else, use our website audit checklist.
Sources
- Google Search Central: How to specify a canonical URL with rel="canonical" and other methods
- Google Search Central: Fix canonicalization issues
- Google Search Central: Pagination, incremental page loading, and their impact on Google Search
- Netlify Docs: Custom headers
- Vercel Docs: Static configuration with vercel.json
Frequently asked questions
Is a canonical tag a directive or a hint?
It is a signal, not a directive. Google describes rel="canonical" as a strong signal and says it may choose a different canonical because of content quality or technical signals. Redirects are equally strong, and sitemap listings are weak. Align all of them so they name the same URL.
Should every page have a self referencing canonical?
Google recommends adding a canonical to the canonical page itself. It costs nothing and protects you when someone links to the page with tracking parameters or a different case, because every variant then points back to the clean URL you chose.
Can a canonical tag point to another domain?
Yes. A cross domain canonical is valid when you publish the same content on two sites you control and want one to be shown. The Google troubleshooting guide notes that for content syndicated to partner sites, the canonical link element is not its recommended approach, so check the Google syndication guidance before relying on it there.
Does a canonical tag pass link signals like a redirect?
Google says one reason to set a canonical is to consolidate signals, such as links, from duplicate pages onto the canonical one. That only works when Google accepts your canonical, so check the selected canonical in Search Console URL Inspection rather than assuming it.
Should I use noindex instead of a canonical for duplicate pages?
Not for duplicates on your own site. Google says it does not recommend noindex to choose a canonical within a site, because noindex removes the page from Search completely instead of consolidating it. Use noindex only for pages you never want in results at all.
Audit your site with your AI coding agent
CrawlKind is a website audit and fix kit for Claude Code: a full crawl, a prioritized findings report, and proposed fixes you review before anything changes. $49 once.