How to Add a Sitemap to Astro
Create a sitemap for your Astro site in three steps, so search engines can find every page. Includes the robots.txt line.
Tested on Astro 7.4

In this guide
A sitemap is a list of your pages that search engines can read. Astro has an official integration that writes one every time you build.
Step 1: Add the integration
Run this in your project folder and confirm the changes:
npx astro add sitemap
Step 2: Set your site’s address
The sitemap needs your site’s full address. Open astro.config.mjs and add site:
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://example.com',
integrations: [sitemap()],
});
Replace https://example.com with your real address, including https://.
Step 3: Build and check
Run npm run build. Two new files appear in dist:
sitemap-index.xml, which points to the other filesitemap-0.xml, which lists your pages
Open sitemap-0.xml and you’ll see one entry for each page, like this:
<url><loc>https://example.com/about/</loc></url>
Tell search engines where it is
Add a line to public/robots.txt. Create the file if it doesn’t exist:
User-agent: *
Allow: /
Sitemap: https://example.com/sitemap-index.xml
It also helps to add a link in your layout’s <head>:
<link rel="sitemap" href="/sitemap-index.xml" />
Finally, submit the sitemap address in Google Search Console once your site is live.
Leaving pages out
Some pages shouldn’t be in a sitemap, like a search page or a thank-you page. Use the filter option:
sitemap({
filter: (page) => !page.endsWith('/search/'),
});
Sitemaps are one part of being found. For the rest, read our Astro SEO guide.
Frequently asked questions
What is a sitemap?
A sitemap is a file that lists every page on your site. Search engines read it to discover pages, especially new ones that nothing links to yet.
Why is my sitemap empty or missing?
The most common cause is a missing site setting in astro.config.mjs. The integration needs your site's full address to build the links.
Stuck on a step?
Check the common errors guide, look up a word in the glossary, or ask in the official Astro Discord, where the support channels are friendly to beginners.