SEO audits › Astro

Astro SEO checklist

Astro ships almost nothing for SEO by default. The framework gives you fast HTML, and the sitemap, robots.txt, canonical tags, redirects and structured data are yours to wire up. This checklist covers each one for an Astro site, with config and code checked against the current Astro docs.

Most of it is a few lines in astro.config.mjs and one shared layout. The parts that go wrong are usually the ones that depend on your host: redirect status codes, trailing slashes and what a missing page returns.

Run a free audit on your Astro site

All 140+ checks, no credit card. Last reviewed 2026-11-26.

Astro sitemap integration: @astrojs/sitemap, SSR, lastmod and sitemap not working

Use the official @astrojs/sitemap integration. Run npx astro add sitemap, set site in astro.config.mjs, and astro build writes sitemap-index.xml and sitemap-0.xml to your output folder.

If your Astro sitemap is not working, check these three things first. One: site is missing. The integration needs your deployed URL, starting with http:// or https://, and produces nothing useful without it. Two: you are requesting /sitemap.xml. The file to open and to submit is /sitemap-index.xml. Three: you are looking in astro dev. The sitemap is generated when you build, so check dist/ after astro build.

SSR is the other common surprise. The integration only lists statically generated routes, including dynamic routes built with getStaticPaths(). It cannot list dynamic routes that are rendered on demand. For those, either pass the URLs in customPages, or serve your own sitemap from an endpoint and add it to the index with customSitemaps.

For lastmod, the top-level lastmod option stamps the same date on every URL, which is rarely true. The integration cannot read your page source, so per-page dates go through serialize(), where you look the date up from your own data.

astro.config.mjs

import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';

// Dates you maintain yourself, for example generated from your content.
const lastmodByPath = {
  '/blog/launch-notes/': '2026-11-02',
};

export default defineConfig({
  site: 'https://example.com',
  integrations: [
    sitemap({
      // Keep noindex and private pages out of the sitemap.
      filter: (page) => !page.startsWith('https://example.com/thank-you/'),

      // Per-page lastmod.
      serialize(item) {
        const date = lastmodByPath[new URL(item.url).pathname];
        if (date) item.lastmod = new Date(date).toISOString();
        return item;
      },

      // A sitemap you serve yourself for on-demand (SSR) routes.
      customSitemaps: ['https://example.com/sitemap-products.xml'],
    }),
  ],
});

The integration does not know which pages carry a noindex tag or a canonical pointing elsewhere, so exclude those with filter. A sitemap should only list URLs that return 200 and that you want indexed.

Full option list: @astrojs/sitemap in the Astro docs.

Wrendex checks for this: Sitemap URL returns 4xx, Sitemap URL redirects, Sitemap URL is noindex, Sitemap URL non-canonical, Invalid sitemap format

Astro robots.txt

Astro does not generate a robots.txt. Add one yourself, either as a static file at public/robots.txt or as an endpoint at src/pages/robots.txt.ts. Both end up at /robots.txt on the built site.

The static file is fine for most sites. Use the endpoint when you want the Sitemap: line to follow the site value in your config so the two never drift apart.

src/pages/robots.txt.ts

import type { APIRoute } from 'astro';

const getRobotsTxt = (sitemapURL: URL) => `\
User-agent: *
Allow: /

Sitemap: ${sitemapURL.href}
`;

export const GET: APIRoute = ({ site }) => {
  const sitemapURL = new URL('sitemap-index.xml', site);
  return new Response(getRobotsTxt(sitemapURL));
};

Do not keep both public/robots.txt and the endpoint. Pick one.

robots.txt controls crawling, not indexing. A Disallow rule stops a crawler from fetching a page, which also stops it from seeing a noindex tag on that page. To keep a page out of search results, use noindex and leave the page crawlable.

Wrendex checks for this: robots.txt inaccessible

Astro canonical URLs with Astro.site and Astro.url

Build the canonical from the current path and your production domain: new URL(Astro.url.pathname, Astro.site). Put it in the <head> of your shared layout so every page gets one.

Astro.site is the site value from your config as a URL. It is undefined when site is not set, so set it. Astro.url is the URL of the page being rendered. On prerendered pages it is built from site and base, and in astro dev it is a localhost URL, which is why you combine the pathname with Astro.site and do not print Astro.url.href directly.

src/layouts/Layout.astro

---
interface Props {
  title: string;
  canonical?: string;
}

const { title, canonical } = Astro.props;
const canonicalURL = new URL(canonical ?? Astro.url.pathname, Astro.site);
---
<html lang="en">
  <head>
    <title>{title}</title>
    <link rel="canonical" href={canonicalURL} />
  </head>
  <body>
    <slot />
  </body>
</html>

Using only pathname drops the query string, which is what you want on on-demand rendered pages where ?utm_source= and similar parameters would otherwise create a new canonical per visit.

Watch trailing slashes. The canonical should match the URL your host serves with a 200, not one that redirects. The trailingSlash and build.format settings in astro.config.mjs affect the paths Astro produces, but for prerendered pages the hosting platform decides how trailing slashes are handled. Crawl the deployed site to find canonicals that point at a redirect or at a different protocol.

Wrendex checks for this: Duplicates without canonical, Canonical points to redirect, Canonical points to 4xx, Non-canonical declared as canonical, Canonical https to http, og:url and canonical disagree

Astro noindex

To noindex a page on an Astro site, render <meta name="robots" content="noindex"> in its <head>. The usual way is a noindex prop on your layout that pages opt into.

For on-demand rendered pages and endpoints you can send the header form instead, which also works for non-HTML responses: Astro.response.headers.set('X-Robots-Tag', 'noindex'). Prerendered pages are plain files, so a header for them has to be configured on your host.

src/layouts/Layout.astro and a page that uses it

---
// src/layouts/Layout.astro
interface Props {
  title: string;
  noindex?: boolean;
}

const { title, noindex = false } = Astro.props;
---
<html lang="en">
  <head>
    <title>{title}</title>
    {noindex && <meta name="robots" content="noindex" />}
  </head>
  <body>
    <slot />
  </body>
</html>

---
// src/pages/thank-you.astro
import Layout from '../layouts/Layout.astro';
---
<Layout title="Thank you" noindex>
  <h1>Thanks, we got your message.</h1>
</Layout>

Then remove the same pages from the sitemap with the filter option of @astrojs/sitemap. The integration cannot see the tag, so it lists noindex pages unless you tell it not to.

The opposite problem is more common: a noindex added for a staging build, or passed as a default in a layout, that reaches production. A crawl shows every page that carries noindex, so you can confirm the list is the one you intended.

Wrendex checks for this: Page is noindex, Conflicting noindex signals, Sitemap URL is noindex, Page became non-indexable

Astro 301 redirects

Define redirects in the redirects object in astro.config.mjs. Whether a visitor gets a real 301 depends on how the site is built and hosted.

Static output with no adapter: Astro writes an HTML file at the old path with a <meta http-equiv="refresh"> tag. That is a client-side redirect. The server answers 200, and any status you set is ignored.

On-demand rendering (SSR), or static output with an adapter that supports it: the redirect is a real HTTP response. The default status is 301 for GET requests and 308 for other methods, and you can set status yourself. With the Netlify adapter, for example, astro build writes your configured redirects to dist/_redirects for Netlify to apply.

astro.config.mjs

import { defineConfig } from 'astro/config';

export default defineConfig({
  redirects: {
    // 301 by default where the server can send one
    '/old-page': '/new-page',

    // Dynamic routes, when both sides use the same parameters
    '/blog/[...slug]': '/articles/[...slug]',

    // External destination
    '/docs': 'https://docs.example.com/',

    // Explicit status code (SSR or a supporting adapter)
    '/sale': {
      status: 302,
      destination: '/pricing',
    },
  },
});

A configured redirect never overrides a real page. If src/pages/old-page.astro still exists, /old-page keeps serving it, so delete or move the file.

If you host static files somewhere with its own redirect rules and no Astro adapter, write the rules in the host's format so they are true 301s. On Cloudflare, for example, that is a _redirects file in public/.

trailingSlash redirects only apply to on-demand rendered pages. For prerendered pages the host handles the slash, and Astro's redirects cannot be used for it.

For a redirect decided at request time, return Astro.redirect('/login') from the page frontmatter. On on-demand routes it defaults to a 302 and takes a status as a second argument, such as Astro.redirect('/products', 301).

After a migration, crawl the old URLs. Wrendex reports meta refresh redirects, chains and redirects that end on a broken page, which are the three ways this usually goes wrong.

Wrendex checks for this: Meta refresh redirect, 302 temporary redirect, Redirect chain, Broken redirect, Redirect loop, Links to redirected page

Astro custom 404 page

Create src/pages/404.astro (or 404.md). Astro builds it to 404.html, and most deploy services find that file and serve it for missing URLs.

On a static site the status code is up to the host. Request a URL that does not exist on the deployed site and confirm the response is a 404 status with your page as the body. A host that answers 200 with the 404 content, or redirects to /404, gives search engines soft 404s.

src/pages/404.astro and returning a 404 from an on-demand route

---
// src/pages/404.astro
import Layout from '../layouts/Layout.astro';
---
<Layout title="Page not found" noindex>
  <h1>Page not found</h1>
  <p><a href="/">Back to the home page</a></p>
</Layout>

---
// src/pages/products/[id].astro
export const prerender = false; // Not needed in 'server' mode

import { getProduct } from '../../lib/products';

const product = await getProduct(Astro.params.id);

// Render the 404 page at this URL instead of redirecting
if (!product) {
  return Astro.rewrite('/404');
}
---
<h1>{product.name}</h1>

On on-demand rendered routes you set the status yourself. Astro.rewrite('/404') renders your 404 page without changing the URL. To set the code explicitly, use Astro.response.status = 404 and render your own markup, or return new Response(null, { status: 404 }). Either way, check the deployed route with curl -I and confirm it says 404.

Avoid Astro.redirect('/404') for missing content. The visitor is sent to a different URL first, and the original URL never reports that it is gone.

For server errors on on-demand routes, src/pages/500.astro works the same way. It is not used for prerendered pages.

Wrendex checks for this: 404 Not Found, 4xx client error, 5xx server error, Links to broken page

Astro meta tags and structured data

Astro has no SEO component built in. You write the <head> yourself, once, in a layout or a Head.astro component, and pass each page's title and description in as props.

For structured data, output JSON-LD with set:html on a script tag. Curly-brace expressions are not evaluated inside a <script> tag, so set:html with JSON.stringify() is the form the Astro docs give for this.

src/components/Head.astro

---
interface Props {
  title: string;
  description: string;
  image?: string;
}

const { title, description, image = '/og-default.png' } = Astro.props;
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
const imageURL = new URL(image, Astro.site);

const schema = {
  '@context': 'https://schema.org',
  '@type': 'WebPage',
  name: title,
  description,
  url: canonicalURL.href,
};
---
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{title}</title>
<meta name="description" content={description} />
<link rel="canonical" href={canonicalURL} />

<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:url" content={canonicalURL} />
<meta property="og:image" content={imageURL} />
<meta name="twitter:card" content="summary_large_image" />

<script type="application/ld+json" set:html={JSON.stringify(schema)} />

Make title and description required props. With TypeScript, astro check then flags any page that forgets them, which is cheaper than finding empty descriptions after launch.

For Markdown and content collection pages, add title and description to the collection schema and pass them through the layout. Titles and descriptions copied from a template are the usual source of duplicates across a blog.

set:html does not escape its value. That is fine for JSON.stringify output built from your own content, but do not pass it unreviewed user input.

Use absolute URLs for og:image and og:url, built from Astro.site as above. A crawl then checks the result on every page: missing or duplicate titles and descriptions, missing Open Graph tags, and JSON-LD that does not parse or is missing fields Google requires.

Wrendex checks for this: Page title missing, Duplicate title across pages, Meta description missing, Duplicate meta description, Missing Open Graph tags, Missing Twitter Card, JSON-LD parse error, Google rich result missing required field, Missing viewport meta

Sources

Check your Astro site now

Wrendex crawls your site the way a search engine does and lists every issue above that it finds, page by page, with how to fix it.

Run free audit

All 140+ checks, free, no credit card.