Start a project

Article · Technical SEO · Sitemaps · Indexing · 12 min read

How to keep an XML sitemap accurate

An XML sitemap is a public list of the URLs you want search engines to treat as the current, indexable site. It is a claim, not a wish list. If the file includes a redirect, a noindex page, a stale campaign URL or a lastmod date that moves every time the template is deployed, you have given crawlers a map they will learn not to trust.

On this page 10 sections
  1. A sitemap is a claim about the site, not a wish list
  2. What to include, and what to leave out
  3. lastmod that only moves when the page really changed
  4. Images, videos and news, when they are worth a file
  5. Finding coverage gaps and leftover URLs
  6. robots.txt, noindex and the sitemap must agree
  7. Automation that does not invent dates
  8. A maintenance routine
  9. Key takeaways
  10. Frequently asked questions

I generate the sitemap on leej.uk from the same release as the HTML, and I built the XML Sitemap Validator and the Sitemap Coverage Diff because a file that slowly drifts from the live site is worse than no sitemap at all. What follows is how I keep the two in agreement.

A sitemap is a claim about the site, not a wish list

Google’s own sitemap documentation describes the file as a way to tell search engines which pages you think are important, and to help them discover URLs they might otherwise miss. That is useful on a site with tools, articles and a few quietly linked legal pages. It is not a ranking lever, and it will not force a thin or blocked URL into the index.

The useful habit is to treat the sitemap the same way I treat a release when I maintain an iOS app after launch: ship the list with the thing it describes, and refuse to list work that is not actually available. The case study on small, focused Apple apps makes the same point in a different context. A sitemap that advertises a URL you took down last month is the web equivalent of an App Store screenshot for a feature you removed.

A short, honest file beats a long, decorative one. Search engines already crawl links. The sitemap’s job is to be the clean, complete set of canonical, indexable URLs, with dates you can defend.

What to include, and what to leave out

Include a URL only when all of these are true:

Leave out, or remove as soon as you find them:

A compact example for a small UK studio site might look like this. The URLs are imaginary; the shape is not:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2026-10-02</lastmod>
  </url>
  <url>
    <loc>https://example.com/work</loc>
    <lastmod>2026-09-18</lastmod>
  </url>
  <url>
    <loc>https://example.com/articles/how-we-quote-a-build</loc>
    <lastmod>2026-11-04</lastmod>
  </url>
  <url>
    <loc>https://example.com/privacy</loc>
    <lastmod>2026-03-12</lastmod>
  </url>
</urlset>

changefreq and priority are still in the Sitemaps protocol. Google has said it ignores them, and I no longer emit them. If another engine you care about still reads them, keep the values honest; do not set every page to 1.0 and hourly.

The XML Sitemap Generator is a reasonable way to get a first file from a list of URLs. It will not decide what should be on the list. That decision is the whole job.

If the site grows past a single file, use a sitemap index and keep each child under the protocol limits (50,000 URLs or 50 MB uncompressed, as the protocol states). Split by type if that makes coverage diffs easier: pages, articles, tools. Do not split just to look complete.

lastmod that only moves when the page really changed

lastmod is the field most sitemaps lie about. The date should be the last time the meaningful content of that URL changed: the title, the body, a price, a policy clause, a heading structure that would alter a snippet. It should not move because you:

Google has been clear that it may use lastmod as a signal when the dates are consistent with reality, and that it may ignore the field when they are not. An always-fresh sitemap trains crawlers to distrust you.

A practical way to set the date:

  1. Prefer a content hash or a source-file mtime for that page, not the time the generator ran.
  2. If the page is built from a markdown file or a CMS record, use the commit or updated-at of that record.
  3. If a shared chrome change really does alter every page in a way that matters to search (a site-wide title suffix, a new canonical host), you can bump every lastmod. That should be rare, and you should be able to say why.
  4. Use W3C date format. A date (2026-11-04) is enough for most small sites; add a time and offset only if you genuinely have that precision.

On this site, a new article or tool lands in the sitemap in the same release that publishes the HTML. The lastmod for /articles moves when the index changes; the lastmod for an older guide does not, unless I edited that guide.

Images, videos and news, when they are worth a file

A page sitemap already helps a crawler find the HTML that embeds an image. A separate image or video sitemap is worth the extra work when the media is the thing you want discovered, and when the files are not easily found by crawling the pages alone.

Typical cases:

Skip a dedicated media sitemap when the site is a handful of pages with decorative images, or when you would only be repeating the same hero photograph on every URL. News sitemaps are for publishers in Google News; a studio blog should not file one for the sake of looking thorough.

If you do need the extra file, the Image and Video Sitemap Generator will shape the XML. The contents still have to be true: working image URLs, captions that appear on the page, and no leaked originals from a staging bucket. Google’s image sitemap and video sitemap documents are the rules to follow, and those rules can be updated, so read them when you first add the file.

List the media sitemap in your sitemap index or in robots.txt the same way you list the page sitemap. Do not leave it as an orphan file only you know about.

Finding coverage gaps and leftover URLs

The two failure modes are opposite, and both show up on small sites:

A coverage check is a three-way comparison, not a glance at the file:

  1. The URLs in the sitemap.
  2. The URLs that are actually live and indexable (from a crawl, from your generator’s page list, or from the same manifest you deploy).
  3. The URLs search engines already know about, if you have a Search Console export.

The Sitemap Coverage Diff is built for the first two lists. Anything in the sitemap but not live is a leftover. Anything live and indexable but not in the sitemap is a gap. Resolve each one: add, remove, or fix the page.

Search Console’s sitemap and page-indexing reports are the third list. They will not always agree with your file on the same day, because crawling and indexing lag. A URL that you added this morning can be missing from the report without being a bug. A URL you removed last month and that still appears as “crawled but not indexed” with a leftover sitemap entry is a bug.

robots.txt, noindex and the sitemap must agree

Pick one story and tell it everywhere. A URL should not be advertised in the sitemap if you have also:

The crawler that honours robots.txt may never see the noindex tag on a disallowed page, and a sitemap entry for that URL just creates a contradiction. If you do not want the page indexed, leave it out of the sitemap and use the right robots mechanism, which is a different article: robots.txt versus X-Robots-Tag.

Mention the sitemap in robots.txt with an absolute URL:

User-agent: *
Allow: /

Sitemap: https://example.com/sitemap.xml

Submit the same URL in Search Console, and in Bing Webmaster Tools if you use Bing. Submitting does not replace a correct file. After a launch, I also ping participating IndexNow engines for new URLs; that is a notification, not a substitute for the sitemap, and it is covered in the IndexNow indexing guide.

Automation that does not invent dates

Once the site has more than a handful of URLs, generate the sitemap in the build, from the same source of truth as the HTML. A hand-edited XML file will fall behind.

The automation should:

That is close to the discipline in the iOS app MVP checklist: do not invent a complete-looking artefact that the product cannot stand behind. A generator that stamps today’s date on 200 unchanged articles is inventing a fact.

I validate the output with the XML Sitemap Validator in the same pass, then run a coverage diff against the live URL list. If either check fails, the sitemap does not ship.

A maintenance routine

A sitemap is not a launch-only task. The routine I use, sized for a site of tens or hundreds of pages, is:

A new site should include the same coverage check in its technical SEO launch checklist. This is not a full-time job on a small site. It is a short, repeatable check. If you cannot keep the file current, keep it small and generated, never hand-curated and forgotten.

Key takeaways

If you want a second pair of eyes on a sitemap that has drifted, tell me about it.

Frequently asked questions

What URLs should be in an XML sitemap?

The canonical, indexable URLs that return 200 and that you want search engines to consider. Home, section indexes, articles, tools, product pages and policy pages usually belong. Redirects, noindex URLs, thank-you pages, staging hosts and parameter duplicates do not.

Should lastmod change when only the template changes?

Not if the change is shared chrome: a footer link, a cache-busting query on a CSS file, or a theme switch. Update lastmod when the substance of that URL changes, or in the rare case that a template change alters something search-relevant on every page, such as the canonical host.

Do I need a separate image or video sitemap?

Only if the images or videos are important to discover in their own right and are not already easy to find from the HTML pages. A small brochure site with a few photographs is usually well served by a page sitemap alone. Follow Google’s current image and video sitemap documentation if you add the extra files.

What if the sitemap lists a noindex or redirected URL?

Remove it. A redirected URL should be replaced by its destination if that destination is indexable. A noindex URL should not be advertised in the sitemap at all; fix the contradiction rather than hoping the search engine will pick the right signal.

How often should a sitemap be rebuilt?

Rebuild it whenever you add, remove or meaningfully edit a URL, ideally in the same release. A monthly coverage check is enough to catch anything the pipeline missed. Rebuilding daily with fresh dates on unchanged pages does not help and can hurt trust in lastmod.

Written by Lee Johnson. Published 10 November 2026.

All articles · Swift A–Z · Apps

Questions, or an app in mind?

Let's bring your ideas to life. Whether you're envisioning a game-changing Apple Watch app or a transformative iOS experience, I'm here to make it happen.

Start a project