Skip to content
Putting technology to work.
Insights to guide decisions and action.

Search articles

[Astro] Add a sitemap for SEO! Configuration guide and caveats

Table of contents · 5 items

Setting up a sitemap is essential for optimizing a website built with Astro for search engines. By properly configuring a sitemap, you make it easier for search engines to understand your site's structure, supporting your SEO efforts.

In this article, we explain how to add a sitemap in Astro and discuss key considerations during setup. Master the basics of sitemap configuration and build a website that stands out to search engines!

What is an Astro sitemap?

A sitemap is a file that hierarchically displays the page structure of a website. By reading the sitemap, search engine crawlers can understand the overall layout of the site and index pages efficiently.

Astro is a framework that enables building high-speed websites as a static site generator. Even for sites built with Astro, configuring a sitemap remains a crucial element. Proper sitemap setup facilitates indexing by search engines, leading to improved SEO.

How to add a sitemap in Astro

To add a sitemap in Astro, follow these steps.

1. Installing the sitemap generation plugin

First, install Astro's sitemap generation plugin, "astro-sitemap." Run the following command in your project's root directory.

npm install astro-sitemap

2. Creating the sitemap configuration file

Next, create a sitemap.config.js file in the root directory of your project and write the sitemap settings.

// sitemap.config.js
export default {
  siteUrl: 'https://gleamhub.net/media',
  generateRobotsTxt: true,
  exclude: ['/404'],
}
  • siteUrl: Site URL
  • generateRobotsTxt: Whether to automatically generate robots.txt
  • exclude: An array specifying pages to exclude from the sitemap

3. Generating and verifying the sitemap

Once the configuration file is created, run Astro's build command to generate the sitemap.

npm run build

When the build finishes, the sitemap-index.xml file will be generated in your project's dist directory. Uploading this file to your server enables search engines to discover your sitemap.

Key considerations when adding a sitemap

1. Configuring pages to include and exclude from the sitemap

There are pages you should include in your sitemap and pages you should omit.

  • Pages to include: Pages you want indexed
  • Pages to exclude: Unpublished pages, duplicate content, etc.

Leverage the exclude option in sitemap.config.js to carefully choose the appropriate pages.

2. Setting sitemap update frequency

It is important to adjust the update frequency of your sitemap to align with how often your site is updated.

While sitemap.config.js does not provide an option to configure update frequencies, make sure to run a build and regenerate it whenever the site updates.

Conclusion

We have explored how to add a sitemap in Astro. Sitemaps play an essential role in helping search engine crawlers understand your site structure.

  • Install the astro-sitemap plugin
  • Configure it properly in sitemap.config.js
  • Automatically generate sitemap-index.xml during build

Pay attention to page selection and update frequency to build an SEO-effective sitemap.

Setting up a sitemap is the first step in search engine optimization. Take advantage of Astro's capabilities to build a website that serves both users and search engines.

Related articles

Share this articleXFacebook
Rui Teruya

Former corporate league baseball player and founder of an IT venture. Founded the company with the drive to ride the fast-moving waves of the world and deliver truly valuable services to society.

Turn this article's theme into your company's next step

Concrete steps forward for your organization.

We organize your desired architecture, legacy systems, and operational requirements to formulate your next steps toward execution.

  • Desired architecture
  • Integration with existing environments
  • Operational requirements
Consult on development & operations initiatives

You can consult with us from the initial conceptual stage. Details from this article will be carried over to the inquiry form.

Receive the latest articles via email · Read the web production guide
Free download

Complete Guide to Web Production: Costs, Vendor Selection & Traffic Acquisition [2026 Edition]

We have compiled cost benchmarks, vendor selection criteria, and traffic acquisition strategies into a PDF.

The PDF and newsletter emails are currently in Japanese.

You will also be subscribed to our newsletter. You can unsubscribe at any time.