Canonical URL is the one address you want search engines to treat as the main version of a page that is reachable at several URLs. You declare it with a link element whose rel attribute is canonical, placed in the head of the page. The link relation is described in RFC 6596, an informational RFC published in April 2012. Google treats the tag as a strong hint, not a command.
The same content often has many addresses: tracking parameters, sort and filter options, http and https, a trailing slash, www and non-www. Without guidance, a search engine picks one itself and may split ranking signals such as inbound links across the copies. A canonical URL tells it which one to keep.
<link rel="canonical" href="https://example.com/shoes"> in the head of every duplicate page, pointing to the preferred URL.The script below shows why duplicates appear. It removes a tracking parameter with the WHATWG URL parser, so two orderings of the same query collapse to one address, while the http version and the trailing-slash version stay different.
const urls = [
"https://example.com/shoes?utm_source=news&color=red",
"https://example.com/shoes?color=red&utm_source=news",
"http://example.com/shoes?color=red",
"https://example.com/shoes/?color=red",
];
for (const u of urls) {
const x = new URL(u);
x.searchParams.delete("utm_source");
console.log(u, "->", x.href);
}
https://example.com/shoes?utm_source=news&color=red -> https://example.com/shoes?color=red
https://example.com/shoes?color=red&utm_source=news -> https://example.com/shoes?color=red
http://example.com/shoes?color=red -> http://example.com/shoes?color=red
https://example.com/shoes/?color=red -> https://example.com/shoes/?color=red
Four addresses, three distinct results. Stripping parameters is not enough: you still choose https, a trailing-slash rule and a host, then point every variant at that choice.
No. Google calls a canonical preference a hint, not a rule, and may choose a different page as canonical. Redirects, internal links, HTTPS and the sitemap all feed that choice. Keep those signals consistent so they all name the same URL.
/shoes works, but it can point at the wrong host if a test copy of the site gets crawled. Write the full https address.