A canonical URL is the address a site names as the preferred version of a page when several addresses return the same content. Most sites name it in a link element in the page head with rel="canonical", and a crawler that reads that element learns which address the site wants kept and which ones it calls copies.
The idea is older than most crawlers in use today. RFC 6596 was published in April 2012 and describes the canonical link as "the author's preferred version of a resource." It is a hint from the site owner. The server returns the page either way, and a crawler decides what to do with the hint.
If you build or run a web scraper, the hint changes how many pages you think a site has. A catalogue whose product answers at a dozen addresses will look like a dozen products to a crawler that counts addresses.
Where the variants come from
A tracking code on a campaign link, a sort order, a session identifier and a download token each give the same content a new address. The RFC uses this case as its example: the canonical link can "specify the preferred version of an IRI from duplicate pages created with the addition of IRI parameters (e.g., session IDs)". Other sources of variants are a trailing slash, an upper-case path, http against https, and www against the bare domain.
A site does not have to be at fault for any of this. A visitor needs the tracking code, and the page has to answer to it. The canonical link is how the site tells a crawler which address stands for the page.
What the element looks like
<head>
<link rel="canonical" href="https://example.com/doc/install">
</head>
The href can be absolute or relative, and RFC 6596 allows it to point at a different host or scheme. It can also point at the page's own address. That form is a self-referential canonical, and Google's documentation recommends it for the canonical page itself.
The head is not the only place. Google's documentation also describes a Link response header with rel="canonical", which a site can send for files that have no HTML head, such as a PDF. This page covers the HTML element, so a page with no element in its head may still name a canonical in that header.
A self-referential canonical says that the page names itself. It does not say that no other address serves the same content, so it settles nothing about duplicates.
What a crawler does with it
The RFC lists three things a search engine can do once a page names its canonical address: take its index content from the target, consolidate signals such as link popularity to the target, and display the target as the representative address. Google's documentation gives the same picture for its own crawler. It lists three signals, redirects, rel="canonical" links and sitemap inclusion, and says of the link: "A strong signal that the specified URL should become canonical."
Notice the word signal. Google adds that when a site names no canonical, it identifies the best version itself. When you write your own crawler the same applies in reverse. The element tells you what the site prefers, and you decide whether to follow it.
How to compare, step by step
This clip compares the canonical of three pages with the address each was fetched at, counts a crawl of 12 pages and sorts the results. The steps follow it in text.
Read the transcript
What a canonical URL is. The address a site names as the preferred version of a page.
One page can answer at many addresses. The canonical names the preferred one. Same content, new address: <link rel="canonical">. utm: A campaign tracking code. session: A session ID. token: A download token.
Resolve the href, compare it with the fetched address as text, and sort the page. /doc/install names itself. /doc/?utm_source=newsletter names /doc/. /doc/install?download=go1.25.linux-amd64.tar.gz names /doc/install. 3 pages fetched. 1 names itself. 2 name another address.
In a crawl of 12 pages every page names itself, and 10 addresses are distinct. /doc/ names itself. /doc/security/ names itself. /gopls/ names itself. /brand names itself. /help names itself. /help names itself. /dl/ names itself. /doc/ names itself. /project names itself. /wiki/ names itself. /conduct names itself. /copyright names itself. 12 pages fetched. 10 distinct addresses. 12 name themselves.
Merge under the canonical, and keep the fetched address as an alias. Three groups: matches, differs, missing. matches: Settles nothing about copies. differs: Compare content, then merge. missing: Check the Link header.
The link names a preferred address. It grants no right to copy or fetch. A hint, not permission: <link rel="canonical">. copy: Terms and copyright apply. fetch: robots.txt sets what you fetch.
Read the full page. The page is at spider.cloud/learn/canonical-url.
- Fetch the page and keep the address you asked for.
- Read the
hrefof thelink rel="canonical"element in the head. If the page has none, record that as a result of its own, and check the response'sLinkheader before you call it missing. - Resolve a relative
hrefagainst the address of the page, then compare the two addresses as text. - Sort the page into one of three groups: the canonical matches the fetched address, it names a different address, or it is missing.
- For the second group, read the content of both addresses before you merge them. If they match, keep the canonical address as the key and record the fetched address as an alias.
Google's documentation gives the reason to prefer the canonical address when you follow links in your own pages: "link to the canonical URL rather than a duplicate URL." Merging also keeps a repeat visit cheap, because a change is recorded once under one key. Sitemaps list the addresses a site would like you to use, which makes them a useful cross-check. A listing that spreads over numbered pages has its own rules, covered on the pagination page, because page 2 is not a copy of page 1.
One crawl, counted
The first run is a crawl of the Go documentation site. It starts at the documentation index, follows links one level out, and stops at 12 pages. The call asks for the raw HTML. The output below keeps the fetched address, the status, the canonical href and the start of the page title (the text before the site name) for each row, cut from the full response. It needs an API key in SPIDER_API_KEY.
curl -s https://api.spider.cloud/crawl \
-H "Authorization: Bearer $SPIDER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://go.dev/doc/", "limit": 12, "depth": 1, "delay": 1000, "request": "http", "return_format": "raw", "user_agent": "examplebot/1.0 (+https://example.com/bot; bot@example.com)"}'
The run was made on 2026-11-21 at 02:14 UTC and took 15.5 seconds for 12 pages. Every page returned status 200 and no error.
https://go.dev/doc/ 200 canonical https://go.dev/doc/ Documentation
https://go.dev/doc/security/ 200 canonical https://go.dev/doc/security/ Security
https://go.dev/gopls/ 200 canonical https://go.dev/gopls/ Gopls: The language server for Go
https://go.dev/brand 200 canonical https://go.dev/brand Brand and Trademark Usage Guidelines
https://go.dev/help 200 canonical https://go.dev/help Help
https://go.dev/help 200 canonical https://go.dev/help Help
https://go.dev/dl/ 200 canonical https://go.dev/dl/ All releases
https://go.dev/doc/ 200 canonical https://go.dev/doc/ Documentation
https://go.dev/project 200 canonical https://go.dev/project The Go Project
https://go.dev/wiki/ 200 canonical https://go.dev/wiki/ Go Wiki: Home
https://go.dev/conduct 200 canonical https://go.dev/conduct Go Community Code of Conduct
https://go.dev/copyright 200 canonical https://go.dev/copyright Copyright
In these 12 rows, every page named its own fetched address as canonical. That holds for these rows only. It says nothing about the pages the crawl did not reach. Two addresses appear twice in the rows, so counting rows gives 12 and counting distinct addresses gives 10. That gap comes from the crawl output and has nothing to do with canonical links.
So the crawl found no variants to compare. That is the reason for a second run. A crawl reaches only the addresses that the pages it reads link to, and the variants this page is about mostly arrive from outside the site: a campaign link in a newsletter, a download link someone shared. A crawl that starts at the index cannot be made to meet them. The second run supplies three addresses by hand, a campaign code and a download token, plus the plain install address for comparison. It is a batch of known addresses sent to the scrape endpoint, not a crawl, and it stands in for the outside links a long-running crawler would pick up over time.
curl -s https://api.spider.cloud/scrape \
-H "Authorization: Bearer $SPIDER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://go.dev/doc/?utm_source=newsletter,https://go.dev/doc/install?download=go1.25.linux-amd64.tar.gz,https://go.dev/doc/install", "request": "http", "return_format": "raw", "user_agent": "examplebot/1.0 (+https://example.com/bot; bot@example.com)"}'
The run was made on 2026-11-21 at 02:15 UTC and took 1.9 seconds for three pages. All three returned status 200 and no error.
fetched https://go.dev/doc/install
canonical https://go.dev/doc/install
title Download and install
fetched https://go.dev/doc/?utm_source=newsletter
canonical https://go.dev/doc/
title Documentation
fetched https://go.dev/doc/install?download=go1.25.linux-amd64.tar.gz
canonical https://go.dev/doc/install
title Download and install
Two of the three named a canonical address that differs from the address fetched. The campaign address named the documentation index, and its title is the same as the one in the crawl above. The download address named the install page, with the same title as the plain install address. Matching titles show only that the titles match. Keep these rows apart until you have compared the content of each address with its canonical target, as step 5 above says.
Do this, avoid this
Do this
- Compare the canonical href with the address you fetched, and record whether it matches, differs or is missing.
- Resolve a relative href against the page address before you compare.
- Read the content of a page and of its canonical target before you merge them.
- Key stored pages by the canonical address and keep the fetched address as an alias.
- Treat a canonical on another host with care, since the site may have set it by mistake.
Avoid this
- Counting each address you fetched as a separate page.
- Dropping a page because its canonical differs, before you have saved what it says.
- Assuming a page is unique because its canonical names itself.
- Reusing a page's text because of its canonical link. The link names a preferred address, and the site's terms and copyright still apply.
A canonical link says nothing about who may copy a page or which paths you may fetch. The robots.txt page covers the file that answers the second question, and the site's terms answer the first. To repeat the count, crawl a site you are allowed to crawl, put each fetched address next to its canonical href, and see how many rows differ.