Sitemap.xml Guide
How to build standards-compliant XML sitemaps and sitemap indexes, curate canonical URLs, automate dynamic sitemap generation, and avoid common crawl signals conflicts.
Sitemap.xml: Architecture & Implementation Guide
A sitemap.xml file is an XML document that lists the canonical URLs on your site that you want search engines to discover and index. While a sitemap does not guarantee that every listed URL will be crawled or ranked, it acts as a direct discovery feed—especially valuable for large sites, newly published content, or pages buried several clicks deep.
sitemap.xml and robots.txt play complementary roles:
sitemap.xmlanswers: "Which canonical URLs exist and should be indexed?"robots.txtanswers: "Which URL paths should crawlers avoid fetching?"
Minimal Valid Structure
A standard XML sitemap must declare the Sitemaps 0.9 XML namespace on a root <urlset> element containing one or more <url> entries. Each <url> requires a <loc> child element:
Every <loc> value must be a fully qualified absolute URL that matches your site's exact canonical protocol (https://), hostname (www vs. non-www), and trailing-slash convention.
Which URLs Belong in sitemap.xml?
Treat your sitemap as a curated list of canonical search landing pages, not a dump of every route your router can resolve.
Include Only URLs That:
- Return
HTTP 200 OK - Are the canonical URL for that content (see the Canonical URL Guide)
- Are publicly accessible without login or authentication
- Contain substantive, index-worthy content
- Are permitted to be crawled by
robots.txtand carry nonoindexdirective
Never Include:
3xxredirecting URLs (301,302,307,308)4xxor5xxerror pages- Pages carrying
<meta name="robots" content="noindex">orX-Robots-Tag: noindex - Non-canonical parameter variants (
?utm_source=...,?sort=price, print views) - Session-bound, checkout, confirmation, user account, or admin routes
- Internal search result URLs (
/search?q=...)
Google Search Console's Page Indexing report offers an All submitted pages filter based strictly on your sitemaps. Keeping non-canonical and redirecting URLs out of sitemap.xml ensures that any Not indexed warning in All submitted pages immediately highlights a real indexing issue. See the GSC Page Indexing Playbook for details.
Core XML Sitemap Elements
<loc> (Required)
Contains the full, XML-escaped canonical URL of the page (& must be escaped as & if query parameters are unavoidable):
<lastmod> (Recommended)
Indicates the date (or ISO 8601 timestamp) when the page's meaningful content last changed:
<lastmod> to the Build Timestamp]
Only update <lastmod> when the page's primary content or structured data actually changes. Resetting <lastmod> to today's date across every URL on every CI/CD deployment destroys signal trust and causes search engines to ignore your <lastmod> timestamps altogether.
<changefreq> and <priority> (Deprecated in Practice)
Although the Sitemaps 0.9 specification defines <changefreq> and <priority>, Google and other modern search engines officially ignore both attributes because site owners overwhelmingly misconfigured them. Omit them to keep your XML payload small and clean, and focus on accurate <loc> and <lastmod> values instead.
Size Limits & Sitemap Index Files
A single XML sitemap file is strictly capped by the protocol at:
- 50,000 URLs maximum per file
- 50 MB (uncompressed) maximum file size
When a site grows beyond these limits—or when you want clean observability per content type in Google Search Console—split your URLs across multiple child sitemaps and reference them from a Sitemap Index (<sitemapindex>):
Partitioning child sitemaps by entity type (rooms.xml, offers.xml, blog.xml) or date range makes it effortless to isolate which section of your site has an indexing drop in Google Search Console. You can also serve gzip-compressed sitemaps (e.g., rooms.xml.gz), provided the uncompressed XML still stays under 50 MB and 50,000 URLs.
Exposing Your Sitemap to Crawlers
1. Reference in robots.txt
Add a top-level Sitemap: directive containing the absolute URL of your sitemap or sitemap index at the bottom of /robots.txt:
The Sitemap: directive is independent of User-agent groups and applies to all crawlers that read robots.txt. Never place your sitemap file inside a directory blocked by a Disallow rule.
2. Submit in Search Engine Webmaster Tools
Submit your sitemap index URL directly in Google Search Console (under Indexing > Sitemaps) and Bing Webmaster Tools to track discovery counts, XML parse errors, and per-sitemap indexing coverage.
Production Example: Hospitality Website
For a hotel or travel website, the sitemap should surface canonical landing pages for rooms, destinations, and promotional offers:
Keep dynamic booking queries and account routes out of the sitemap:
Automating Dynamic Sitemaps in Application Code
Never maintain sitemap.xml by hand for CMS- or database-driven sites. Generate your sitemap dynamically from the exact same data source and routing logic that renders your canonical pages:
- Query only published, indexable records: Filter by
status = 'published'andnoindex = falseat the database/CMS query layer. - Use the canonical URL helper: Construct
<loc>using the same canonical URL builder that powers your<link rel="canonical">tags so trailing slashes and slugs never diverge. - Map
<lastmod>to content update timestamps: ReadupdatedAtfrom the CMS record rather thannew Date(). - Chunk automatically: Paginate database queries into child sitemaps whenever a collection approaches 50,000 items.
- Cache with smart invalidation: Serve the XML with
Content-Type: application/xml; charset=utf-8and cache it at the CDN edge (Cache-Control: public, max-age=3600, stale-while-revalidate=86400), purging on CMS publish webhooks.
Common Sitemap Anti-Patterns
Pre-Deployment Checklist
- Every
<loc>is an absolute canonical URL returningHTTP 200 OK. - Zero URLs in the sitemap are blocked by
robots.txt, markednoindex, or redirecting (3xx). - XML is well-formed UTF-8 and served with
Content-Type: application/xml(ortext/xml). - Each sitemap file stays under 50,000 URLs and 50 MB uncompressed.
-
<lastmod>reflects true content modification timestamps in ISO 8601 format (YYYY-MM-DD). - The root sitemap or sitemap index is declared via
Sitemap:in/robots.txtand submitted in Google Search Console. - Verify the live sitemap with the Robots + Sitemap Inspector.