The Astro SEO Guide: Canonicals, Hreflang, and Structured Data
A practical guide to multilingual SEO in Astro: self-referencing canonicals, bidirectional hreflang, clean HTML output, and valid structured data.
Astro builds fast, static-first sites. That same philosophy pays off for search engines: content ships as clean HTML with no client-side rendering in the way. But shipping a multilingual site well is about more than translating strings. It is about telling search engines exactly which page is canonical and how language versions relate to one another.
This guide covers the essentials.
Self-referencing canonicals
Every indexable page should declare itself canonical. A self-referencing canonical resolves ambiguity when duplicate content appears across query parameters or session links. In Astro, derive the canonical from the configured site and the current pathname so you never hardcode a hostname.
https://mysite.com/article/astro-seo-guide
should output:
<link rel="canonical" href="https://mysite.com/article/astro-seo-guide" />
Hreflang is bidirectional
When a Turkish translation exists at /tr/makale/astro-seo-rehberi, both pages should announce each other. English references Turkish, and Turkish references English. Use a shared translation identifier rather than hardcoding a URL map, so the relationship stays correct as content grows.
<link rel="alternate" hreflang="en" href="https://mysite.com/article/astro-seo-guide" />
<link rel="alternate" hreflang="tr" href="https://mysite.com/tr/makale/astro-seo-rehberi" />
Never fabricate a language variant that does not exist. If a translation is missing, omit that hreflang entry entirely.
One canonical, always
A page must not contain two canonical tags or a canonical that points elsewhere. og:url should match the canonical. For translated pages the canonical is the page itself, not the English version.
Structured data that matches the page
Article structured data should reflect the localized headline, description, and language. Emit inLanguage, datePublished, and dateModified from real frontmatter. Do not invent authors, ratings, or facts that do not appear on the page.
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "The Astro SEO Guide",
"inLanguage": "en"
}
Validate the built output
A build that compiles is not proof of correct SEO. Inspect the generated HTML, not just the components. Check the title, description, canonical, hreflang, html lang, and JSON-LD for each language version before you ship.