1. Self-Referencing Canonicals & Clean XML Sitemaps
A common static-site bug is hardcoding a single root canonical inside a shared layout file, telling search engines that every subpage duplicates the homepage. Resolving canonicals dynamically from `Astro.url.pathname` and `Astro.site` fixes duplicate-content ambiguity across all routes.
Equally critical, `@astrojs/sitemap` should explicitly filter out `/400`, `/403`, `/404`, and `/500` error pages while `robots.txt` blocks utility/error paths cleanly.
// astro.config.mjs — Exclude Error Routes from Sitemap Index
sitemap({
filter: (page) =>
!['/400', '/403', '/404', '/500'].some(
(err) => page.endsWith(err) || page.endsWith(`${err}/`)
),
})