Astro sitemap setup: generate, filter, and check the deployed XML
Configure @astrojs/sitemap with the correct site origin, identify sitemap-index.xml, handle missing dynamic pages, and inspect the deployed output before submission.
Install the integration and set the public origin
Use the official @astrojs/sitemap integration and set site to your canonical production origin in Astro's configuration. The integration creates a sitemap index and numbered sitemap files during the build. Start with the generated index rather than assuming your endpoint is named /sitemap.xml.
The configuration below follows the official integration documentation checked on October 7, 2026. The customSitemaps option later in this guide requires @astrojs/sitemap 3.5.0 or later. Adapt it to your existing config and installed version; keep the production domain consistent with canonical tags and links.
npx astro add sitemap
// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://example.com',
integrations: [sitemap()],
});Know which file contains page URLs
The index can load correctly while a child file returns HTML or a 404. Check both levels. A browser's XML display is not enough to show that every listed route resolves to the right page.
| File | Contains | How to inspect it |
|---|---|---|
| sitemap-index.xml | Links to child sitemap files | Open each listed child; do not count these entries as pages |
| sitemap-0.xml | Page URL entries | Review canonical URLs, route coverage, and exclusions |
| Additional numbered files | Further page URL batches | Inspect the children actually referenced by the index |
Filter pages that should not be listed
Make the filter match your route rules. A path-based filter handles the account route without depending on a trailing slash or a particular host string. Do not rely on a sitemap filter to protect account data; authentication still belongs on the application route.
For a blog, ensure unpublished content is excluded in the route-generation logic as well as the sitemap. Omitting a page from a sitemap does not make an otherwise public URL private or unindexable.
// Merge into your existing Astro configuration.
sitemap({
filter: (page) => {
const path = new URL(page).pathname;
return path !== '/account' && !path.startsWith('/account/');
},
})Handle missing server-rendered or external routes deliberately
Compare the generated output with an inventory of your important public routes. Build-time generation cannot discover every runtime-only URL from a database. Astro's integration provides customPages for additional page URLs and customSitemaps for external sitemap files; verify support in your installed version.
Only include routes you intend to be public and canonical. For a large runtime catalogue, a separately maintained sitemap endpoint may be a better source than manually listing every item in configuration. Keep its publication and deletion rules aligned with the actual pages.
sitemap({
customPages: ['https://example.com/runtime-public-page'],
// Where supported by your installed integration:
customSitemaps: ['https://example.com/catalog/sitemap.xml'],
})Make the sitemap discoverable
Point the declaration to the index that your production deployment actually serves. You can also submit that URL in Search Console. A successful sitemap submission establishes that Google read the file; it does not establish that every listed page is indexed.
# public/robots.txt
User-agent: *
Allow: /
Sitemap: https://example.com/sitemap-index.xmlCheck the deployment before submitting
- Open /sitemap-index.xml on the production domain while signed out.
- Inspect the HTTP status, final URL, and XML body, then open every relevant child sitemap.
- Confirm there are no localhost, preview-domain, private, deleted, or duplicate parameter URLs in the page entries.
- Compare important routes with the exported URL list and investigate missing sections.
- If a child returns HTML, inspect hosting rewrites and the deployed build artifacts before resubmitting.
Related practical guides
Continue with guides on the same launch or SEO task, then apply what you learned to your own product.
Ready for a pre-launch audit?
Run the public analyzer and get a prioritised report for the URL you are about to share.
Run the SEO audit