Scobly

Guides · 2026-11-08 · 11 min read

XML Sitemap Best Practices for Google and Bing Indexing

Learn how to generate clean XML sitemaps, filter out non-200 and non-canonical URLs, automate accurate lastmod timestamps, and speed up indexing.

A structured tree of clean document cards with green checkmarks and calendar timestamp badges feeding through a filter gate into two crawler inbox trays, while faded redirect and error slips drop into a side bin.

TL;DR

  • Include only HTTP 200 OK, self-referencing canonical URLs in your XML sitemap and strip out redirects, 404s, and noindex pages.
  • Skip deprecated priority and changefreq attributes so crawlers focus on accurate loc and lastmod fields.
  • Update ISO 8601 lastmod timestamps only when a page's primary content changes, never on every deployment.
  • Split sitemaps before hitting 50,000 URLs or 50 MB and organize child sitemaps by route type under a sitemap index.

What you need

You ship a batch of new product pages or blog posts, wait two weeks, and open your search console reports only to find those URLs sitting unindexed. Often, the culprit is an outdated or bloated XML sitemap that wastes crawler attention on redirects, error pages, and unchanged routes.

Before you overhaul your sitemap generation pipeline, make sure you have the following access and tools ready:

  • Codebase or CMS access: Permission to edit the routing logic, build scripts, or server endpoints that generate your XML files.
  • Git history or database timestamps: A reliable record of when each page's primary content was actually created or modified.
  • Google Search Console access: Owner or full user permissions for your verified domain or URL-prefix property.
  • Bing Webmaster Tools access: Administrative access to your verified site dashboard and API settings.
  • Thirty to sixty minutes: Enough time to audit your current URL output, update your build script, and verify the new submission.

1. Audit Current URLs and Filter Out Non-200 and Non-Canonical Pages

An XML sitemap is a direct list of URLs you want search engines to crawl and index. When your sitemap includes redirects, broken links, or duplicate pages, search engines start distrusting the file's signals.

Every URL in your XML sitemap must return an HTTP 200 OK status code and declare itself as the canonical version of the page. If a URL redirects, shows a 404 status, or points its canonical tag elsewhere, filter it out at build time before writing the XML file.

URL Categories to Exclude Immediately

Audit your route generator against your application's middleware and page metadata so these common offenders never enter your sitemap:

  • Query parameter variations: Filter, sort, and pagination URLs or session tracking parameters that duplicate primary listing pages.
  • Staging and preview URLs: Internal testing domains, pull request preview builds, or canary routes that accidentally share production database tables.
  • Utility and state pages: Thank-you pages, password reset flows, empty search result templates, and shopping cart endpoints.

How to Enforce Canonical Consistency in Code

Many modern web frameworks build sitemaps by iterating over file-system routes or database records without checking how the server responds to those paths. If your routing table adds a trailing slash or forces lowercase characters at request time, your sitemap generator must apply that exact same normalization function before writing the URL.

Follow these checks in your route collector to guarantee every entry matches your live canonical URLs:

  1. Share a single URL resolver: Call the exact same helper function to generate both your HTML canonical link tags and your XML sitemap entries.
  2. Filter by published status: Query your CMS or database with an explicit filter that excludes draft, archived, unlisted, and scheduled records.
  3. Check route-level metadata: Inspect each page's metadata object during the build and skip any route where the robots directive includes noindex.
  4. Validate dynamic route slugs: Cross-check dynamic URL slugs against active database records so deleted items never produce soft-404 entries in your XML output.

URL States in XML Sitemaps

URL State Include in Sitemap Crawler Impact Required Action
200 OK self-canonical Yes Crawled and prioritized for indexing Keep and maintain accurate lastmod
301 or 302 redirect No Wastes crawl budget following hops Replace with final destination URL
404 or 410 error No Triggers sitemap processing errors Remove from sitemap output immediately
Meta noindex tag No Sends conflicting indexation signals Filter out pages flagged as noindex
Canonicalized to another URL No Splits signals between duplicate URLs Include only the target canonical URL
Blocked by robots.txt No Crawler cannot fetch page contents Remove from sitemap or unblock route

2. Generate Valid XML Sitemap Markup and Skip Deprecated Tags

Once your route list is filtered down to clean, indexable URLs, format the output strictly according to the Sitemaps XML protocol specification. Search parsers are strict: a single unescaped ampersand or missing namespace attribute can cause crawlers to reject the entire file.

A standards-compliant XML sitemap requires only a handful of structural elements:

  1. Declare UTF-8 encoding: Start the file on line one with the standard XML version and UTF-8 encoding declaration without leading whitespace.
  2. Open the urlset root element: Include the standard sitemaps.org 0.9 namespace attribute inside the root urlset element.
  3. Wrap each page in a url entry: Create one url parent block for every canonical 200 OK page on your site.
  4. Provide the absolute loc address: Inside the loc element, write the full URL including the HTTPS scheme, exact subdomain, and trailing slash convention.
  5. Include an accurate lastmod date: Add the lastmod element containing an ISO 8601 date or timestamp only when you can verify the exact modification time.
  6. Escape special characters: Convert ampersands, single quotes, double quotes, and angle brackets into their corresponding XML entity codes.

Tip: Leave the changefreq and priority elements out of your sitemap generator. According to Google Search Central's documentation on building sitemaps, Google completely ignores both values because webmasters routinely set every page to daily and maximum priority.

Skipping unused tags reduces file size, speeds up generation during builds, and keeps the markup focused on the two fields search engines actually evaluate: the URL location and its last modification date.

Preventing Common XML Parsing Failures

Rather than concatenating raw strings in a loop, use a dedicated XML serializer or structured builder library in your server language. String templates break easily when a URL contains unexpected characters or when middleware injects debugging comments into the response stream.

Check your generated output against these parser requirements before deploying:

  • Zero leading whitespace: Ensure no blank lines, byte-order marks, or HTML comments appear before the opening XML declaration on line one.
  • Consistent protocol and host: Verify that every entry uses your production HTTPS domain rather than localhost, an internal container hostname, or an HTTP fallback.
  • RFC-3986 URI encoding: Percent-encode non-ASCII characters in URL paths before applying XML entity escaping so internationalized routes parse cleanly.

3. Automate Accurate lastmod Timestamps From Content Changes

Both Google and Bing rely heavily on the lastmod field to decide whether to recrawl a known URL. However, according to Bing Webmaster Tools' sitemap best practices guide, search engines will ignore your timestamps if your build script stamps every URL with the current deployment time on every release.

To keep search engines trusting your sitemap, wire your code to update a page's lastmod value only when its meaningful content changes. Minor footer tweaks, CSS updates, or global navigation edits do not count as page modifications.

How to Wire True Modification Dates in Code

Follow this five-step pipeline in your build or server logic to generate trustworthy timestamps:

  1. Read source timestamps: Pull the updated-at column from your CMS database for dynamic pages, or query the Git commit timestamp of the specific Markdown or template file for static routes.
  2. Hash the primary content body: During the build, compute a fast cryptographic hash of each page's main article or product data, excluding global headers, footers, and scripts.
  3. Compare against the previous build: Check the new content hash against the cached hash from your last production deployment.
  4. Update lastmod on diff only: If the hash changed, write the new timestamp in W3C Datetime (ISO 8601) format; if the hash is identical, preserve the existing timestamp.
  5. Omit unknown dates: If a route aggregates live data where you cannot track a meaningful edit timestamp, omit the lastmod element for that URL rather than guessing.

When formatting ISO 8601 dates, include the full date and time with the UTC offset (such as 2026-11-05T14:30:00Z) or the calendar date (2026-11-05) consistently across all entries. In CI/CD environments that clone repositories with shallow history, configure your checkout step to fetch full Git history so file commit timestamps do not default to the current build time.

Watch out: When you deploy a sitewide layout change or fix a typo in a shared component, make sure your Git-based timestamp lookup ignores global layout files. Otherwise, a single header commit will reset the modification date across thousands of untouched pages.

Stamping every URL with the deployment time makes search engines ignore your lastmod dates.

4. Split Large Sitemaps With a Sitemap Index File

The sitemaps protocol enforces hard limits on individual XML files: a single sitemap cannot exceed 50,000 URLs or 50 megabytes uncompressed. Even if your SaaS site or content library has only a few thousand pages, splitting your single file into smaller sitemaps organized by page type makes debugging indexation bottlenecks much easier.

As documented in Google's guide to managing large sitemaps, you can group multiple child sitemaps under one master sitemap index file. The index file uses a sitemapindex root element instead of urlset, and points to each child sitemap's URL.

Structure your child sitemaps along clear architectural boundaries:

  • Segment by content type: Create separate child files for marketing landing pages, blog posts, documentation guides, and programmatic directory pages.
  • Chunk programmatic routes in batches: Cap high-volume child sitemaps at 10,000 to 25,000 URLs per file so you stay well below the 50,000 URL ceiling.
  • Serve gzip-compressed files: Compress large XML files using gzip (ending in .xml.gz) to reduce bandwidth usage and speed up crawler downloads.
  • Roll up child lastmod dates: Set each child sitemap's lastmod value inside the sitemap index file to equal the most recent modification timestamp among the URLs inside that child file.

When you submit a sitemap index alongside its child files in Google Search Console or Bing Webmaster Tools, both dashboards break down index coverage metrics by individual child sitemap. You can immediately spot whether indexing drops are isolated to documentation pages, blog posts, or programmatic templates.

5. Declare Your Sitemap in robots.txt and Submit to Google and Bing

Generating a clean XML sitemap at build time only helps if crawlers can find it immediately and read it without server restrictions. Your deployment checklist should expose the sitemap in three places: your robots.txt file, Google Search Console, and Bing Webmaster Tools.

Complete these verification and submission steps right after deploying your updated sitemap:

  1. Verify headers and status: Fetch your live sitemap URL to confirm it returns an HTTP 200 status and an application/xml or text/xml Content-Type header.
  2. Add the Sitemap directive to robots.txt: Place a Sitemap line at the bottom of your robots.txt file specifying the full HTTPS URL of your sitemap or sitemap index.
  3. Submit in Google Search Console: Open the Sitemaps report in your Search Console property, paste the relative path of your sitemap, and submit it to verify Google reads zero errors.
  4. Submit in Bing Webmaster Tools: Add the full sitemap URL under the Sitemaps section in Bing Webmaster Tools and inspect the discovered URL count.
  5. Allow sitemap routes through your WAF: Ensure CDN rules, bot protection challenges, and rate limiters allow automated search crawlers to fetch your XML files without hitting CAPTCHAs or 403 blocks.

Never password-protect or geo-block your sitemap routes. If a search crawler hits a firewall block or a temporary 500 error while reading your sitemap index, it will pause processing for all child URLs until the next scheduled fetch.

A firewall block or 500 error on the sitemap index pauses processing for all child URLs.

6. Monitor Sitemap Coverage and Automate Checks With Scobly

A developer might add a redirect to an old route, mark a template as noindex, or break a dynamic route without updating the sitemap filter.

FAQ

Does Google still use the priority and changefreq tags in XML sitemaps?

No, Google ignores both the priority and changefreq elements in XML sitemaps. You should omit them from your sitemap generator and focus on providing clean canonical URLs with accurate lastmod timestamps.

How many URLs can a single XML sitemap file contain?

A single XML sitemap file can hold at most 50,000 URLs and must not exceed 50 megabytes uncompressed. If your site grows past those limits, or if you want cleaner coverage reports in Google Search Console, split your URLs across multiple child sitemaps linked from a sitemap index file.

Should I include paginated or query-parameter URLs in my XML sitemap?

Only include a URL if it returns a 200 status code, is meant to rank in search results on its own, and has a self-referencing canonical tag. Filtered views, sort parameters, and non-canonical pagination URLs should be excluded so crawlers focus on your primary pages.

Sources

Meet yours today.

Today is the least it will ever know about your site.