How to Add a Sitemap to Your Astro Site

A sitemap helps search engines discover and index all the pages on your Astro website. This guide shows you how to add a sitemap using the official @astrojs/sitemap integration.

Why You Need a Sitemap

Sitemaps are XML files that list all the URLs on your site. They help search engines like Google and Bing:

  • Discover new and updated pages faster
  • Understand your site structure
  • Prioritize crawling important pages

Step 1: Install the Sitemap Integration

Astro provides an official sitemap integration. Install it with your package manager:

npx astro add sitemap

Or install manually:

npm install @astrojs/sitemap

Step 2: Configure Your Astro Config

Add the sitemap integration to your astro.config.mjs and set your site URL:

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

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

Step 3: Build and Verify

Run npm run build and check your dist/ folder for sitemap-index.xml and sitemap-0.xml. Your sitemap will be available at:

https://yourdomain.com/sitemap-index.xml

Advanced: Customizing Your Sitemap

You can customize which pages are included, set change frequencies, and add priorities:

sitemap({
  filter: (page) => !page.includes('/admin/'),
  changefreq: 'weekly',
  priority: 0.7,
  lastmod: new Date(),
})

Submit to Search Engines

Once your sitemap is live, submit it to:

Related Guides

Need a ready-made Astro template?

Check out our hand-picked premium Astro templates with SEO best practices built in.