Safeguard
Developer Tools•

Canonical URLs for versioned docs: which version should rank?

When v1, v2 and latest docs pages overlap, use redirects and rel=canonical consistently. Google's ranked methods and the mistakes that split your signals.

Safeguard Security Team
3 min read

For versioned docs, pick the version you want people to land on, usually the current one, and point duplicate or near duplicate pages at it with one consistent method. Google lists redirects as strongest, rel=canonical as strong, and sitemap inclusion as weak. Mixing methods that disagree is the common failure.

What a canonical URL is

Google describes the canonical URL as the preferred version when duplicate or very similar pages exist. Specifying one helps Google show your preferred URL, consolidate signals such as links, and avoid spending crawl time on duplicates.

The methods, strongest first

  1. Permanent redirects from the duplicate to the preferred URL. Use them only when you are retiring the duplicate.
  2. A rel="canonical" annotation, in the HTML head or as an HTTP header. The header works for non HTML files such as PDFs. Pick one approach, not both.
  3. Sitemap inclusion, a weak signal. Google treats listed URLs as candidates.

Applying it to versions

Two situations differ.

If old versions are still useful, such as v1 docs for people on v1, they are not true duplicates. Let them be indexable with their own self referential canonical, and make them clearly labeled. A reader on v1 deserves to find v1.

If an old page is nearly identical to the current one, canonicalize to the current page, or redirect when you are removing the old URL.

A common pattern is a stable "latest" path that always shows the current docs, with each numbered version at its own path. Decide which one search should prefer and be consistent.

Rules from Google's guidance

  • Include a self referential canonical on the canonical page.
  • Use absolute URLs, not relative paths.
  • Link internally to the canonical URL.
  • Do not point different methods at different canonicals for the same page.
  • Do not use robots.txt or noindex to choose a canonical within a site.
  • Do not use URL fragments as canonicals.
  • With JavaScript, put the canonical in the initial HTML and do not let scripts change it.

Example tags

<link rel="canonical" href="https://example.com/docs/latest/install">

Placed on /docs/2.0/install if 2.0 is current, and a self referential tag on every other page that should stand alone.

Check your work

Use URL Inspection in Search Console to see which URL Google selected as canonical. If it differs from yours, look for conflicting signals: a sitemap listing the old URL, internal links pointing to it, or a redirect loop.

Google also says it generally prefers HTTPS over HTTP, so make sure your canonicals use HTTPS.

Quick check

Does a canonical tag guarantee Google uses my URL?

No. It is a signal. Google decides, and conflicting signals can override yours.

Should the sitemap list old versions?

List the URLs you want indexed. A listed URL is a canonical candidate, so do not list pages you have canonicalized elsewhere.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.