XML sitemaps should describe the pages you want search engines to discover, not every URL your system can technically emit.
That sounds obvious until a publishing stack starts mixing drafts, scheduled pages, soft-deleted records, staging leftovers, noindex templates, and pages that exist for users but should not be surfaced for search. Once those states are all represented in the same database, sitemap generation becomes less about “creating a file” and more about deciding which URLs are eligible to be advertised at all.
The cleanest rule is usually this: only include canonical, indexable, publicly accessible URLs that are in a published state. Everything else should be excluded by default unless you have a deliberate reason to do otherwise.
Start with eligibility, not exclusion
Teams often ask how to remove noindex pages from sitemaps, but the better design is to define sitemap eligibility from the source of truth.
That means the sitemap generator should not inspect random page attributes and then guess. It should consume a clear publish-state model, for example:
draftscheduledpublishedarchiveddeleted
Then layer in indexing eligibility:
- the page is published
- the page resolves with a 200 status code
- the canonical points to itself or another approved canonical target
- the page is not blocked from crawling in a way that makes inclusion misleading
- the page is not marked
noindex - the page is not otherwise disallowed by business rules for sitemap inclusion
This avoids a common failure mode: a page is hidden from navigation, tagged noindex, but still sits in the sitemap because the generator only checked whether the record existed.
If you are already building rules around indexability, this fits naturally with broader publishing controls such as automated noindex rules and a sitemap index for millions of URLs. The same principle applies in both places: the sitemap should reflect controlled publishing state, not just raw content inventory.
Exclude unpublished pages at the database layer
Unpublished pages are the easiest to handle if your sitemap is generated from database records rather than from crawled HTML.
If a record is not published, do not emit it.
That may sound too simple, but it is the right simplification. Scheduled pages are especially easy to mishandle because they are “real” in the CMS and may already have slugs, metadata, and internal references. None of that means they belong in a live sitemap. A scheduled page should usually remain absent until the publish event actually occurs.
The practical implementation is usually one of these:
- filter on a
published_attimestamp that must be present and in the past - filter on a
status = publishedfield - require a publication workflow event before the page is added to the sitemap feed
- generate the sitemap from a publish index rather than from the full content table
The last option is often the most robust at scale. It separates “content exists” from “content is eligible for discovery,” which prevents accidental leakage from drafts, preview pages, and incomplete records.
Exclude noindex pages with a rule, not a manual cleanup step
Noindex pages should usually be removed from XML sitemaps because the sitemap is a discovery hint and noindex is a direct signal not to index the page.
If both signals point in opposite directions, you are creating avoidable ambiguity. Search engines can still crawl a noindex page if they discover it elsewhere, but there is little reason to advertise it in a sitemap unless you have a very specific operational case.
The right way to handle this is to make the noindex state machine-readable. Do not rely on someone remembering to remove URLs from a sitemap manually.
A good sitemap eligibility check can look like:
- page status is published
- robots meta is not
noindex - X-Robots-Tag is not
noindex - canonical is valid and indexable
- page is not blocked by a site-wide policy that removes it from sitemaps
This is also where teams can get tripped up by inconsistent rendering. A page might look indexable in the CMS, but the final HTML template injects noindex conditionally. If sitemap generation happens before render-time logic is applied, the sitemap can become out of sync with the page that actually ships.
That is why sitemap generation and metadata generation should share the same source of truth or the same rules engine. If you are already generating dynamic metadata in a framework such as Next.js, keep sitemap eligibility aligned with the same data model rather than duplicating logic in two places. The more times you re-encode “should this page be indexed?” the more opportunities you create for drift.
Decide what to do with canonicalized pages
Some pages are published and indexable in a technical sense, but they are not the version you want in the sitemap.
Examples include:
- alternate URL variants
- tracking parameter URLs
- duplicate regional or language URLs when the canonical points elsewhere
- template-driven variants that should resolve to a primary URL
For these, the sitemap should usually include only the canonical destination, not every variant that happens to exist.
That matters because sitemap inclusion is partly about clarifying site architecture. If the sitemap contains multiple URLs that all consolidate to one canonical destination, you are sending conflicting discovery signals.
This is especially relevant in systems that also have to manage URL changes without breaking internal links or redirect mapping during migrations. If a URL is no longer meant to be surfaced as the primary version, the sitemap should stop advertising it as such.
Use status codes and response behavior as a safety check, not the main rule
It is tempting to build sitemap logic by crawling live URLs and including anything that returns 200.
That is too late in the process.
Response checks are useful as a validation layer, but not as the primary publishing rule. A page can return 200 and still be wrong for the sitemap because it is:
- unpublished in the CMS
- marked noindex
- a preview or test route
- a duplicate variant
- intentionally excluded from search
Use live response behavior to catch mismatches, not to define eligibility from scratch. A good QA job for a sitemap system compares the generated URL set against the rules you expect and then samples live URLs to catch drift.
For example:
- published pages missing from the sitemap
- noindex pages still included
- unpublished pages exposed by mistake
- canonicalized duplicates listed as primary URLs
- pages that return non-200 responses but remain in the sitemap
Those checks are closely related to how teams monitor indexing after publishing at scale. If you already track published pages missing from Google or indexing after scaling SEO publishing, sitemap validation belongs in the same operating layer: it is a control for discovery quality, not just a file-generation task.
Keep the rules deterministic and inspectable
The more ambiguous your sitemap logic becomes, the harder it is to debug when something goes wrong.
Good sitemap systems make it easy to answer three questions:
- Why was this URL included?
- Why was this URL excluded?
- Which rule changed its status?
That usually means storing inclusion reasons alongside the output or in a build log. For example:
excluded: unpublishedexcluded: noindexexcluded: canonical points elsewhereexcluded: blocked by site policyincluded: published, indexable, canonical self
This is useful when content, SEO, and engineering teams disagree about whether a URL “should have been there.” The answer should not depend on tribal memory. It should come from a rule that is visible in the system.
Do not use sitemaps as a substitute for fixing publishing logic
When teams discover unpublished or noindex pages in a sitemap, the wrong response is sometimes to bolt on a manual exclusion list.
That can hide the symptom while leaving the system broken.
If your sitemap keeps surfacing the wrong URLs, the issue is usually upstream:
- content states are poorly modeled
- noindex is applied inconsistently
- preview URLs are too easy to reach from production systems
- canonical logic is not shared across templates
- the sitemap generator is reading the wrong data source
A durable fix usually means tightening the content model and aligning the sitemap with the same state that powers rendering, robots directives, and canonical tags. That creates fewer exceptions to maintain and fewer ways for pages to drift out of policy.
The best sitemap setups are boring in the right way. Published pages appear. Drafts do not. Noindex pages stay out. Canonical targets are represented once. And when a page changes state, the sitemap updates because the system understands the state change—not because someone remembered to edit a file.