SEO · Content Systems · Publishing Infrastructure

How to Generate Sitemaps for Thousands of Pages

Learn how to generate XML sitemaps for thousands of pages from your source of truth, segment large URL sets, keep canonical URLs aligned, remove stale URLs, and validate sitemap deployment.

If you need to generate sitemaps for thousands of pages, the main problem is not writing XML. It is deciding which system owns the URL list, when a URL becomes eligible, and how the sitemap stays in sync as pages are published, updated, redirected, or removed.

At larger scale, a sitemap should be treated as an output of your publishing system, not a separate SEO artifact. That means the sitemap is built from the same records that determine page state, canonical URL, and indexability. If those inputs are inconsistent, the sitemap becomes a lagging hint instead of a reliable discovery feed.

Start from the source of truth

The safest pattern is to generate sitemap entries from a page registry in your CMS, database, or content service. That registry should contain, at minimum:

  • the canonical URL
  • publication state
  • indexability state
  • last modified timestamp
  • page type or segment
  • redirect status
  • canonical target if the page is not self-canonical

This matters because URL discovery is a systems problem. If the sitemap is assembled from a hand-maintained list, it will drift. Pages that were unpublished may linger. Drafts may leak in. Redirected URLs may continue to be advertised. A sitemap generated directly from the source of truth avoids that mismatch.

For teams building larger publishing systems, this is the same general principle behind what an SEO content system is: the outputs only stay coherent if the content registry, templates, metadata, and publish state are connected.

Only include URLs that deserve discovery

A sitemap is not a dump of every route your application can render. It should include URLs you want search engines to crawl and consider for indexation.

In practice, that usually means:

  • published pages only
  • canonical URLs only
  • pages that return a 200 status
  • pages not blocked by robots rules
  • pages not marked noindex
  • pages that are not thin duplicates or temporary states

You can be more permissive or more selective depending on the site, but the rule should be explicit. If the sitemap includes pages that are intentionally excluded from indexing, you are sending mixed signals. Search engines can usually sort through some noise, but there is no reason to create it.

This becomes especially important on large sites where page eligibility is conditional. If you are already modeling whether a page is ready to be discovered, the sitemap should reflect that same eligibility logic, not a separate guess.

Respect sitemap limits by design

The XML sitemap protocol has practical limits: a single sitemap file should not exceed 50,000 URLs or 50MB uncompressed. Those limits are generous enough for many sites, but they are not generous enough for one monolithic file once page counts grow.

The usual solution is a sitemap index file that points to multiple sitemap files. That gives you room to segment by page type, publication date, business unit, locale, or some other operational boundary.

A useful rule is to segment for maintenance first and SEO second. Good segmentation makes it easier to identify broken slices, stale slices, or unexpected drops in published URLs.

Common segmentation patterns include:

  • /sitemaps/pages-1.xml
  • /sitemaps/blog-1.xml
  • /sitemaps/products-1.xml
  • /sitemaps/us-en-1.xml
  • /sitemaps/2026-01.xml

The exact scheme matters less than consistency. If a developer or SEO engineer can tell what changed from the filename, you have a workable system.

If your site architecture is already split by rendering or page model, the sitemap structure should usually mirror that. A page architecture guide like programmatic SEO architecture becomes useful here because sitemap segmentation tends to follow the same database and template boundaries that shape the rest of the site.

Build around publication state, not build state

A common mistake is to generate sitemap URLs from what exists in the build output rather than what is actually published. That can work for static sites with simple release patterns, but it becomes fragile once drafts, scheduled publishing, partial deploys, or async content updates enter the system.

For large sites, sitemap generation should usually happen after the page has reached a published state in your content system. If a page is present in the rendered frontend but not yet approved for indexing, it should not appear in the sitemap. If a page has been retired or redirected, it should disappear from the sitemap as part of the same state change.

That is also why deployment and publishing need to be connected. A sitemap is not just a file artifact generated at the end of a build. It is a representation of what is currently live and eligible.

Keep canonical URLs aligned

Every URL in the sitemap should correspond to the canonical version of that page. If the page has a preferred URL, the sitemap should point to it directly rather than to parameterized, alternate, or tracking variants.

That sounds obvious, but scale creates edge cases:

  • a page exists at both a clean URL and a legacy URL
  • locale variants are all renderable, but only some should be indexed
  • pagination or filter states accidentally get included
  • trailing slash and non-trailing slash versions coexist

The sitemap should not try to resolve those ambiguities on its own. The canonical decision should happen earlier in the stack, and the sitemap should consume that decision.

If your canonical logic is still evolving, fix that first. A sitemap cannot correct a weak URL model; it only reveals it.

Remove stale URLs quickly

Large sites tend to accumulate stale URLs because page creation is easy and page removal is neglected. A sitemap makes that problem visible, but it can also prolong it if removal is slow.

When a page is deleted, merged, or redirected, the sitemap should update on the same deployment or publish event that changed the page state. Do not leave old URLs in the sitemap for convenience. Search engines already have other discovery paths; the sitemap should not keep promoting URLs that no longer exist or no longer represent the current page.

This is where sitemap generation overlaps with content maintenance. If your team already uses a refresh-and-retire process, such as the one described in SEO content maintenance, the sitemap should be wired into that lifecycle rather than treated as a separate cleanup task.

For redirected URLs, the general rule is simple: the final destination belongs in the sitemap, not the redirect source.

Generate sitemap files as part of deployment

The cleanest implementation is usually a small automated job in your build or publishing pipeline:

  1. read eligible published pages from the source of truth
  2. filter to canonical, indexable 200-status URLs
  3. group URLs into segments
  4. emit sitemap XML files
  5. emit a sitemap index file
  6. deploy the files with the site

That job can run during build time for static systems or during publish time for CMS-driven systems. The important thing is that it runs predictably and atomically enough that the public sitemap does not reference pages that are not yet live.

If you operate a hybrid rendering setup, the generation point depends on your architecture. The tradeoff between rendering and build strategy affects not only page delivery but also how quickly the sitemap can reflect changes. The same operational tension is discussed in Static Generation vs SSR for Large SEO Sites.

A practical implementation detail: keep the sitemap generation job deterministic. If the same source records produce different sitemap outputs without a content change, debugging becomes unnecessarily hard.

Validate the output before and after deployment

Sitemap generation fails in boring ways: malformed XML, oversized files, missing namespace declarations, stale index references, or URLs that do not match the live site. Those are predictable enough that they should be checked automatically.

Good validation usually includes:

  • XML schema or structural validation
  • URL count and file size checks
  • verification that all URLs return 200
  • verification that canonical URLs match sitemap URLs
  • detection of non-indexable URLs
  • detection of redirect chains or 4xx/5xx responses
  • confirmation that the sitemap index references live child files

It is also worth comparing the sitemap output to your page registry. If the registry says 12,000 pages are eligible but the sitemap contains 11,400 URLs, that gap deserves investigation.

For teams with a broader publishing workflow, this validation belongs alongside the checks described in what should happen technically when you publish an article. The sitemap is one step in the publish lifecycle, not a separate quality gate.

Monitor sitemap health as a system

Once the sitemap is live, do not assume it stays correct. Monitor it the way you would monitor any other production artifact.

Useful signals include:

  • number of URLs per sitemap segment
  • number of sitemap files in the index
  • last generation timestamp
  • mismatch between eligible pages and sitemap URLs
  • spikes in 404s or redirects among sitemap URLs
  • dropped sitemap fetches or parse failures
  • unexpected changes in file size or URL distribution

In Search Console, sitemap submission and processing feedback can help surface issues, but it should not be your only signal. By the time a manual review reveals a structural problem, the sitemap may already have been inaccurate for days or weeks.

The operational goal is simple: if your site can publish hundreds or thousands of pages, your sitemap system should tell you when the registry, publish state, or URL model stops matching reality.

A practical rule of thumb

If a human has to decide each time whether a URL belongs in a sitemap, the system is too manual for the scale you are operating.

The better approach is to encode sitemap eligibility in the same rules that govern publishing:

  • Is the page published?
  • Is the URL canonical?
  • Is the page indexable?
  • Does it return 200?
  • Has it been removed, merged, or redirected?

When those answers are stored in your source of truth, generating sitemaps for thousands of pages becomes a mechanical output of the publishing system rather than a recurring SEO task.

That shift matters because it turns sitemap management from file editing into infrastructure. And once it is infrastructure, it can be versioned, tested, deployed, segmented, and monitored like everything else that keeps a large site coherent.

← Back to SEO Infrastructure