Discoverability · Astro
How to set canonical URLs correctly in Astro
A canonical tag pointing at the wrong target tells search engines to index that page instead of this one — every page pointing at the homepage removes your whole site from search except one URL, while everything still looks correct in a browser. With no canonical at all, the same page reached through a tracking parameter, a trailing slash or the www host can be treated as several competing pages.
The fix for Astro
13x detects your framework from the response and hands you this version rather than the generic one — below 50% confidence it hedges and gives you the generic one instead.
Use Astro.url so each page is self-referencing:
---
const canonical = new URL(Astro.url.pathname, Astro.site);
---
<link rel="canonical" href={canonical} />Astro.site comes from the site option in astro.config.mjs, so set that too.
On a different stack? The general version of this fix explains what 13x checks and why it matters, without assuming a framework.
Check your Astro site
113 deterministic checks against your live URL, in about 30 seconds. Framework detected from the response, so every fix comes back in the form your stack actually uses.
No signup. Results in 30 seconds.