Redirects and canonicals Required
Make every canonical signal agree
Give each page one canonical address, and make the canonical tag, sitemap, Open Graph address, hreflang links and internal links all use exactly that address.
How to do it
Build the canonical from the public origin and the page's path, as an absolute, self-referencing HTTPS address without tracking parameters or a fragment. Put exactly one <link rel="canonical"> in the <head>, because Google ignores it in the body and drops conflicting ones. For non-HTML copies such as Markdown or PDF, send it as a Link: <…>; rel="canonical" header. Use the tag or the header, not both. Never point a canonical at a redirect, a 404 or a noindex page. Don't use noindex or robots.txt to choose a canonical, because they hide the page instead.
Example
<link rel="canonical" href="https://example.com/guides/caching">
<meta property="og:url" content="https://example.com/guides/caching">
link: <https://example.com/guides/caching>; rel="canonical"
How to check
A test reads each page's canonical, og:url and sitemap entry and expects the same address, answering 200 without a redirect. Each page has exactly one canonical tag. The Lighthouse canonical audit passes.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers website playbook: https://agentwranglers.se/playbook/website/redirects-and-canonicals/canonical-signals.