How to Add a Sitemap to Astro
Make 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. Search engines read it to find them all. Astro has an official integration that writes one each time you build. An integration is an add-on for Astro. A build is making the finished copy of your site.
Step 1: Add the integration
Run this in your project folder. Say yes to the changes it offers:
npx astro add sitemap
Step 2: Set your site’s address
The sitemap needs your site’s full address. Open astro.config.mjs. This is your site’s settings file. 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. Include the https:// part.
Step 3: Build and check
Run npm run build. Two new files appear in dist. That is the output folder that holds your finished site.
sitemap-index.xml. This one points to the other file.sitemap-0.xml. This one lists your pages.
Open sitemap-0.xml. You will see one entry for each page. It looks like this:
<url><loc>https://example.com/about/</loc></url>
Tell search engines where it is
Add a line to public/robots.txt. Make the file if it is not there yet:
User-agent: *
Allow: /
Sitemap: https://example.com/sitemap-index.xml
It also helps to add a link in your layout’s <head>. The layout is the shared frame around every page:
<link rel="sitemap" href="/sitemap-index.xml" />
Last, submit the sitemap address in Google Search Console. Do this once your site is live.
Leaving pages out
Some pages should not be in a sitemap. A search page, say, or a thank-you page. Use the filter option:
sitemap({
filter: (page) => !page.endsWith('/search/'),
});
A sitemap is 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 find pages, above all 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 the friendly people in the official Astro and EmDash Discords. How to ask so people can help.