Skip to content
← All articles

Guides

Sitemap, redirects and favicon in Astro: the pre-launch checklist

Before an Astro site goes live: set site, pick one trailing-slash style, clean up the sitemap, make redirects real 301s on your host, ship a small favicon set and keep staging out of Google.

Vas 14 min read
Ask AI about this article ChatGPT Claude Perplexity .md

Your Astro site looks done. Before you point the domain at it, spend 30 minutes on three small things that quietly decide how Google sees your site: the sitemap, redirects and the favicon. Get them wrong and you lose old rankings, index duplicate URLs or show a generic globe icon in search results.

This guide walks through each one with copy-paste code. It is written for Astro 6 and 7 and works for static sites as well as sites with an adapter.

A word on honesty first: we sell Astro templates, and at the end we say what they already include.

Current as of November 17, 2026. The latest versions are Astro 7.4.12 and @astrojs/sitemap 3.7.5. Hosts change their limits and defaults, so check the date.

The short checklist

  • site is set in astro.config.mjs to your real production URL
  • One trailing-slash style everywhere: links, canonicals, sitemap, host
  • @astrojs/sitemap installed, and sitemap-index.xml opens in the browser
  • 404, thank-you and draft pages filtered out of the sitemap
  • lastmod is either a real content date or not set at all
  • robots.txt points to sitemap-index.xml
  • Every old URL redirects to its new URL in one hop, with a real 301
  • Redirects work on your host, not just in astro dev
  • Favicon set in public/: favicon.ico, icon.svg, apple-touch-icon.png
  • Favicon tags are on the home page
  • Staging and preview URLs send noindex
  • Sitemap submitted in Google Search Console and Bing Webmaster Tools

Step 0: tell Astro where the site lives

The sitemap, canonical tags and absolute social-image URLs all depend on one setting: site. Without it, the sitemap integration skips the sitemap. The build still passes, with only a warning in the log, so this is easy to miss.[1]

// astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  site: 'https://example.com',
  trailingSlash: 'always',       // or 'never': just pick one
  build: { format: 'directory' } // 'directory' pairs with 'always', 'file' with 'never'
});

Why the slash matters: /about and /about/ are two different URLs to Google.[22] If your sitemap lists one and your host serves the other, every sitemap entry points at a redirect, and Google crawls URLs you don’t want indexed (our assessment).

One catch: Astro’s trailingSlash setting only covers the dev server and pages rendered on demand. For prerendered (static) pages, your host decides what /about returns.[3] So set the same rule on the host too, for example trailingSlash in vercel.json.[13]

Only set base if the site lives in a subfolder, like example.com/docs. Most sites don’t need it.

Sitemap: install it, then clean it up

The official @astrojs/sitemap integration builds the sitemap on every build. Install it with one command:[1]

npx astro add sitemap

This adds it to your config:

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

export default defineConfig({
  site: 'https://example.com',
  integrations: [sitemap()],
});

Run npm run build and look in dist/. You get two files:[1]

  • sitemap-index.xml: the file you submit to search engines
  • sitemap-0.xml: the actual list of pages (big sites also get sitemap-1.xml and so on)

Keep junk pages out

The integration adds every page it builds, including ones you don’t want in Google: the 404 page, a thank-you page after a form, drafts. It does not read a page’s noindex meta tag, so you exclude them yourself:[1]

sitemap({
  filter: (page) =>
    !page.includes('/404') &&
    !page.includes('/thank-you') &&
    !page.includes('/drafts/'),
}),

The page value is the full URL, including your domain.

Be honest about lastmod

Google ignores changefreq and priority, so don’t bother setting them. It does read lastmod, but only if the dates are consistently and verifiably accurate.[6]

The common mistake is lastmod: new Date(). That stamps every page with the build time, so every page looks freshly updated on every deploy, and search engines learn to ignore it. Either leave lastmod out, or pass real dates from your content:

// astro.config.mjs
const updated = {
  'https://example.com/blog/my-post/': '2026-10-02',
  // build this map from your blog frontmatter (updatedDate)
};

sitemap({
  serialize(item) {
    if (updated[item.url]) item.lastmod = updated[item.url];
    return item;
  },
}),

Pages rendered on demand

The sitemap only sees pages built at build time. Pages rendered on demand with dynamic URLs are not included. Add them through the customPages option, which takes a list of full URLs.[1]

Tell the browser and search engines

Add a link in your main layout’s <head>:[1]

<link rel="sitemap" href="/sitemap-index.xml" />

Then, after launch, submit https://example.com/sitemap-index.xml (the index, not sitemap-0.xml) in Google Search Console and Bing Webmaster Tools.[6]

robots.txt: point crawlers to the sitemap

The simplest option is a plain file in public/:

# public/robots.txt
User-agent: *
Allow: /

Sitemap: https://example.com/sitemap-index.xml

If you’d rather not hard-code the domain, generate it from site with an endpoint:[1]

// src/pages/robots.txt.ts
import type { APIRoute } from 'astro';

export const GET: APIRoute = ({ site }) => {
  const sitemapURL = new URL('sitemap-index.xml', site);
  return new Response(
    `User-agent: *\nAllow: /\n\nSitemap: ${sitemapURL.href}\n`
  );
};

Since Astro 6, endpoints with a file extension, like /robots.txt, are only served without a trailing slash, whatever your trailingSlash setting.[4]

One warning: don’t block staging with Disallow: / and then copy that file to production by accident. For staging, use a noindex header instead (see Keep staging out of Google below).

Redirects: the part most guides get wrong

If you are replacing an old site, redirects are how you keep its rankings. Astro lets you declare them in the config:[2]

// astro.config.mjs
export default defineConfig({
  redirects: {
    '/old-page': '/new-page',
    '/blog/[...slug]': '/articles/[...slug]',
    '/pricing-2025': { status: 302, destination: '/pricing' },
  },
});

A static route can only redirect to a static route, and a dynamic one to a dynamic one with the same parameters. So '/article': '/blog/[...slug]' won’t work.[3] The object form with a status also needs on-demand rendering or an adapter: a plain static build can’t send status codes.[3]

What actually reaches the browser

This is the important bit. The same config produces different results depending on how you deploy:[3]

How you deploy What a redirect becomes Permanent server redirect?
Static build, no adapter An HTML page with an instant <meta http-equiv="refresh"> No
Static build + _redirects or vercel.json you write A server redirect from the host Yes, if you set the status (see below)
Netlify or Vercel adapter Native host redirect rules, generated from your config Yes
On-demand page A server response: 301 for GET, 308 for other methods Yes

Does the meta refresh hurt SEO? Not badly: Google treats an instant meta refresh as a permanent redirect. But Google’s own advice is to use a server-side redirect whenever you can and to keep meta refresh as a fallback.[7] If you’re on a static host, add a _redirects file.

Writing your own _redirects file

Netlify and Cloudflare both read public/_redirects:[11, 12]

# public/_redirects
/old-page        /new-page        301
/blog/*          /articles/:splat 301

Always write the status code: without it, Cloudflare sends a 302, a temporary redirect.[12]

Vercel uses vercel.json instead:[13]

{
  "redirects": [
    { "source": "/old-page", "destination": "/new-page", "statusCode": 301 }
  ]
}

You’ll often see "permanent": true instead. That sends a 308,[13] which Google also treats as permanent.[7]

If you declare redirects in the Astro config but serve them through _redirects or vercel.json, set build: { redirects: false } so Astro stops writing the HTML redirect pages.[3] On Netlify, a file at the old path would otherwise win over your redirect rule.[19]

Redirects in code

For logic like “send logged-out users to /login”, use Astro.redirect() in an on-demand page:[15]

---
if (!user) return Astro.redirect('/login', 307);
---

It defaults to 302 (temporary). On a prerendered page it becomes a meta refresh with no status code. Middleware can do the same with context.redirect().[15]

Moving from WordPress or another site

  1. Export every URL that gets traffic: from Search Console and the old sitemap.
  2. Map each old URL to its final new URL. One hop only: never /a → /b → /c.[7]
  3. Match the trailing-slash style you chose in Step 0.
  4. Put long lists in _redirects or vercel.json. Keep the Astro config for a handful of rules.
  5. Check that every new page has a canonical tag pointing to itself.

If your site is multilingual

In Astro 6, i18n.routing.redirectToDefaultLocale changed its default to false, and it now works only together with prefixDefaultLocale: true. If you relied on / redirecting to /en/, set both explicitly, or the root URL may stop redirecting after an upgrade.[4]

Favicon: three files are enough

A new Astro project ships with public/favicon.svg and public/favicon.ico, both the Astro logo.[21] Replace them before launch. You don’t need a generator that outputs 30 files. Three files cover browsers, phones and Google:[9]

File (in public/) Size Used by
favicon.ico 32×32 Older browsers, RSS readers, anything that asks for /favicon.ico
icon.svg Any (vector) Modern browsers, supports dark mode
apple-touch-icon.png 180×180 iPhone and iPad home screen

Add these tags to your layout’s <head>:

<link rel="icon" href="/favicon.ico" sizes="32x32" />
<link rel="icon" href="/icon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />

The sizes="32x32" on the ICO line is deliberate: it stops Chrome from choosing the ICO over the sharper SVG.[9]

If the site should install as an app (a PWA), add a web manifest with 192×192 and 512×512 PNG icons and link it with <link rel="manifest" href="/manifest.webmanifest" />. A regular marketing site doesn’t need it.[9]

Dark mode in one SVG

A dark logo disappears on a dark browser tab. Put a media query inside the SVG:[9]

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
  <style>
    path { fill: #111; }
    @media (prefers-color-scheme: dark) { path { fill: #fff; } }
  </style>
  <path d="..." />
</svg>

Getting your favicon into Google results

Google shows a favicon next to your result only if:[8]

  • The <link rel="icon"> tag is on your home page
  • The icon is square and at least 8×8 px; Google recommends larger than 48×48 px
  • Googlebot can crawl the home page and Googlebot-Image can crawl the icon file: neither is blocked in robots.txt
  • The URL stays the same. Don’t change it often

After a change, Google picks up the new icon when it recrawls your home page, which can take days to weeks. Requesting indexing of the home page in Search Console can help.[8]

Favicon not updating?

Browsers cache favicons hard. For the SVG and PNGs, rename the file (icon.v2.svg) and update the tag. Keep /favicon.ico at the same path, since some tools only ever ask for that exact URL.

If you use base

With base: '/docs', a hard-coded /icon.svg returns 404. Build the path from the base instead:

<link rel="icon" href={`${import.meta.env.BASE_URL}icon.svg`} type="image/svg+xml" />

Check whether BASE_URL ends with a slash in your setup; it depends on trailingSlash.[3]

There are favicon integrations for Astro (astro-favicons, astro-favicon-kit), but for a normal site, a few static files in public/ are simpler and add no dependency (our assessment).

Host-specific notes

A fully static Astro site needs no adapter on any of these hosts. The differences are in redirects, 404 pages and preview URLs.

Cloudflare Workers Netlify Vercel
Redirects public/_redirects: up to 2,000 static and 100 dynamic rules[12] public/_redirects or netlify.toml[11] vercel.json[13]
Custom headers public/_headers _headers or netlify.toml[20] vercel.json[13]
404 page Set not_found_handling to "404-page" in wrangler.jsonc[5] Serves 404.html automatically[19] Serves 404.html automatically
Preview URLs indexed? Preview URLs get noindex; your *.workers.dev address does not, so add it yourself[17] Deploy previews and older branch deploys get noindex; the latest deploy of a branch does not[18] Previews get noindex; a custom domain assigned to a branch does not[10]

Cloudflare

Cloudflare recommends Workers for new projects.[5] If you use the @astrojs/cloudflare adapter for on-demand pages, note that since version 13 it deploys to Workers only and no longer supports Cloudflare Pages.[16] A purely static site needs no adapter, so this doesn’t affect it.

For a static site on Workers, point the assets at dist and deploy:[5]

// wrangler.jsonc
{
  "name": "my-site",
  "compatibility_date": "2026-11-17",
  "assets": {
    "directory": "./dist",
    "not_found_handling": "404-page"
  }
}
npx astro build && npx wrangler deploy

Without not_found_handling, your 404.astro page won’t be served. The full walkthrough, from GitHub to your own domain, is in “How to publish an Astro site on Cloudflare”.

Keep staging out of Google

Use a response header, not robots.txt. If you block crawling, Google can’t see the noindex and may still index the URL.[14] Send this header from the staging deploy only:

/*
  X-Robots-Tag: noindex

On Cloudflare, put it in the _headers file of the staging Worker. On Netlify, _headers applies to every deploy, so copy a staging-only _headers file into the output in the staging context’s build command.[20]

The safer option is to redirect the *.workers.dev, *.netlify.app or *.vercel.app address to your real domain once it’s live.

Check it on the live site

astro dev doesn’t tell you what your host will do. Test the deployed site with curl -I, which shows only the response headers.

Does the old URL return a real 301, in one hop?

curl -sIL https://example.com/old-page | grep -iE "^HTTP|^location"

You want to see 301 (or 308), then one location, then 200. A 302 means the status is missing from your rule, and two location lines mean a redirect chain.

Does a missing page return a real 404, not 200?

curl -sI https://example.com/this-does-not-exist | head -1

Is staging marked noindex?

curl -sI https://my-site.netlify.app | grep -i x-robots-tag

Finally, open sitemap-index.xml and spot-check a few URLs. Each one should return 200 directly, match its canonical tag and not be noindex. Then submit the sitemap in Search Console and use URL Inspection on the home page to request indexing.[6]

Every ShipThemes template ships with this done

ShipThemes templates are complete Astro sites for SaaS, AI products, studios and law firms. Every one of them, Nodezy, Systemizy, LawFirm, SWG Studio and the free Smoketest, ships with this checklist already done:

  • The site address in one place (SITE_URL, or product.url in Smoketest’s single settings file), with no placeholder domain in the build, and one URL style: every page address ends with a slash.
  • A clean sitemap: the 404 and other noindex pages are left out, lastmod comes only from real content dates, and robots.txt points to it.
  • A full favicon set: favicon.ico, favicon.svg, an Apple touch icon, 192 and 512 px icons and a web manifest, linked on every page.
  • A working 404 page that Cloudflare Workers serves out of the box.
  • Ready-made redirect files for Cloudflare and Netlify (_redirects) and Vercel (vercel.json), with real 301s. The build warns when they drift from astro.config.mjs.
  • A “Before you launch” section in the README with the host notes and the staging noindex header.

You set your domain, swap in your icons and launch. What stays yours: redirects for your old site’s URLs and submitting the sitemap in Search Console.

Frequently asked questions

Does Astro make a sitemap automatically?

Not by itself. Add the official @astrojs/sitemap integration and set site in astro.config.mjs; the sitemap is then built on every build.[1]

Do Astro redirects return a 301?

It depends on the deployment. A static build without an adapter writes an HTML page with an instant meta refresh. With a Netlify or Vercel adapter you get a server redirect from the host; with your own _redirects file, write the 301 in each rule.[3, 12]

Where do I put the favicon in an Astro project?

In public/, with the <link rel="icon"> tags in your main layout’s <head>, so they end up on the home page.[8]

Why doesn’t my Astro 404 page show on Cloudflare?

Set "not_found_handling": "404-page" in the assets block of wrangler.jsonc. Without it, Cloudflare doesn’t serve 404.html for missing pages.[5]

Sources

Pages checked on November 17, 2026.

  1. Astro Docs, @astrojs/sitemap
  2. Astro Docs, Routing (redirects)
  3. Astro Docs, Configuration reference
  4. Astro Docs, Upgrade to Astro v6
  5. Astro Docs, Deploy your Astro site to Cloudflare
  6. Google Search Central, Build and submit a sitemap
  7. Google Search Central, Redirects and Google Search
  8. Google Search Central, Define a favicon to show in search results
  9. Evil Martians, How to Favicon in 2026: Three files that fit most needs (updated January 21, 2026)
  10. Vercel Docs, Environments: are preview deployments indexed by search engines?
  11. Netlify Docs, Redirects and rewrites
  12. Cloudflare Docs, Workers static assets: Redirects
  13. Vercel Docs, vercel.json: redirects
  14. Google Search Central, Block search indexing with noindex
  15. Astro Docs, Astro render context (redirect())
  16. Astro Docs, @astrojs/cloudflare
  17. Cloudflare Docs, Workers: Preview URLs
  18. Netlify Docs, Branch deploys
  19. Netlify Docs, Redirect options (shadowing, custom 404 page)
  20. Netlify Docs, Custom headers
  21. Astro on GitHub, examples/basics/public (the starter’s favicon files)
  22. Google Search Central Blog, To slash or not to slash (April 21, 2010)
All templates →

From the blog

Keep reading

All articles

Ready when you are

Launch your next site this week.

Pick a template, pay once, download instantly. Every page is already designed. You bring the words.