Astro.site

Astro.site is the URL configured as the project's site option, or undefined if unset.

Since Astro 1.0 Spec ↗

Syntax

const canonical = new URL(path, Astro.site)

Returns

URL | undefined — A URL built from the site config value, or undefined when not configured.

Examples

---
const canonical = new URL(Astro.url.pathname, Astro.site);
---
<link rel="canonical" href={canonical.href} />
Output
Outputs an absolute canonical URL based on the configured production domain.

Notes

Set site in astro.config.mjs. Essential for absolute URLs in sitemaps, RSS feeds, Open Graph tags, and canonical links. It is undefined if not configured, so guard or always set it.

See also