Sitemaps should not include redirecting URLs
The @astrojs/sitemap integration includes your redirect page in the sitemap, but it shouldn't.
When your site root redirects to /blog (or anywhere else), that redirecting URL should not appear in the sitemap. Google states that all pages listed in a sitemap are suggested as canonicals. If a URL redirects, the redirect target is canonical.1
The @astrojs/sitemap integration includes every page by default, including redirect pages. Pass a filter function to exclude them.
Usage
// astro.config.ts
import sitemap from "@astrojs/sitemap";
export default defineConfig({
site: "https://example.com",
integrations: [
sitemap({
filter: (page) => page !== "https://example.com/",
}),
],
});
The filter function receives the full URL of each page. Return false for the URLs you want to exclude from the sitemap.
I noticed this on frangonf.com, where the root redirects to /blog via Astro.redirect("/blog", 301). The root URL was still listed in sitemap-0.xml as the first <url> entry. After adding the filter, it’s gone.
Notes
- This only matters for URLs that redirect; canonical pages still belong in the sitemap
- The filter compares full URLs (including the
sitefrom your config), not route paths - For GitHub Pages static sites, the redirect compiles to a
<meta refresh>withnoindexand acanonicaltag. Google treats instant meta refresh redirects as permanent redirects, which is the best you can do without server-side redirect support
References
- Google. How to specify a canonical URL
- Google. Redirects and Google Search
- Astro. @astrojs/sitemap
- Astro. Redirects
- Webmasters SE. Sitemap with redirecting URLs
Footnotes
-
If you include redirecting URLs in your sitemap, Google Search Console will warn you that “we found that some URLs redirect to other locations” and recommend replacing them with the final destination URL. ↩
This post was written with AI assistance.