Technical SEO
XML sitemap best practices: what to include, what Google ignores, and how to check yours
The core XML sitemap best practices: list only the canonical, indexable URLs that return 200: no redirects, 404s, noindexed pages or parameter duplicates. Google ignores the priority and changefreq tags and uses lastmod only when it is consistently accurate, so set it to the last real content change or leave it out. Keep each file under 50,000 URLs and 50MB uncompressed, put it at the site root, and submit it in Search Console and robots.txt.
What should an XML sitemap include?
Only the URLs you want people to land on from Google. Google's Build and submit a sitemap guide puts it plainly: "Include the URLs in your sitemap that you want to see in Google's search results." Since Google generally shows canonical URLs, that means one entry per page, in the exact form you chose as canonical.
A good test for each URL: if a visitor typed it into the browser, would they get a 200 response, the page itself (no redirect), and a page you would be happy to see in results? If any answer is no, the URL does not belong in the file.
| URL type | Include? | Why |
|---|---|---|
| Live, indexable pages (home, services, articles, products) | Yes | These are what the sitemap is for |
Pages with noindex | No | You are asking Google to crawl a page and then telling it not to index it |
| URLs that redirect (301, 302, 307, 308) | No, list the final URL | Google crawls URLs "exactly as listed," so every redirect is a wasted hop |
| 404 and 410 URLs | No | Search Console flags submitted URLs that fail |
Duplicates that canonicalize elsewhere (?sort=, ?utm_, print versions) | No | List only the canonical; a mismatch sends mixed signals |
| URLs blocked by robots.txt | No | Google cannot fetch them, so it cannot read them |
| Login, cart, account, search results, thank-you pages | No | Nobody should arrive at these from search |
| Staging or preview hosts | No | Only production URLs on your canonical host |
Source: Google Search Central, Build and submit a sitemap (last updated November 27, 2026). If you are unsure whether a page should be blocked or noindexed, our guide to noindex vs robots.txt covers that decision.
Which sitemap tags does Google ignore?
Two of the four standard tags do nothing for Google. The build guide says: "Google ignores <priority> and <changefreq> values." Google repeated this in its June 2023 post retiring the sitemaps ping endpoint, which said it still does not use either element.
| Tag | Required? | What Google does with it | What to do |
|---|---|---|---|
<loc> | Yes | Crawls the URL exactly as written | Absolute, canonical, escaped URL |
<lastmod> | No | Uses it only if it is "consistently and verifiably" accurate | Include it if you can generate a true date; otherwise leave it out |
<changefreq> | No | Ignored | Drop it to keep the file small |
<priority> | No | Ignored | Drop it |
Source: Google Search Central, Build and submit a sitemap, read November 2026. Other search engines may read these tags differently; the sitemaps.org protocol still defines all four. Leaving changefreq and priority in place does no harm. The cost is only false confidence that setting priority to 1.0 on your home page does something in Google.
Google also says the order of URLs "doesn't matter," so there is no need to sort important pages to the top.
How should you set lastmod so Google trusts it?
Set it to the date of the last real change to the page and nothing else. Google's wording: "The <lastmod> value should reflect the date and time of the last significant update to the page." It counts changes to "the main content, the structured data, or links on the page" as significant, and says "an update to the copyright date is not."
The common failure is a generator that stamps every URL with the build time. Every deploy then claims all 300 pages changed today, the dates stop matching reality, and Google has a reason to disregard them. Because Google uses lastmod only when it is "consistently" accurate, a pattern of false dates can cost you the signal across the whole file.
Use the W3C datetime format: either a date (2026-11-20) or a date and time with a time zone (2026-11-20T14:30:00+00:00). Formats such as 20/11/2026 are invalid.
Good sources for a true date, in order of reliability:
- An
updated_atfield your CMS sets when an editor saves real content changes. - The last Git commit that touched the page's source file (the script below does this).
- A
modifieddate stored in the page's front matter, if your team keeps it honest.
One trap with the Git approach, which we reproduced while writing this: in a shallow clone, every file reports the date of the single commit that was fetched. GitHub Actions' actions/checkout fetches one commit by default, so set fetch-depth: 0 before generating dates, or every page gets today's date.
How do you build a valid sitemap.xml file?
A minimal valid file looks like this. The namespace line is required, the file must be UTF-8, and every loc is a full URL:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.example.com/</loc>
<lastmod>2026-11-20</lastmod>
</url>
<url>
<loc>https://www.example.com/pricing/</loc>
<lastmod>2026-10-02T14:30:00+00:00</lastmod>
</url>
</urlset>
Rules from Google's build guide and the sitemaps.org protocol that trip people up:
- Absolute URLs only. "Use fully-qualified, absolute URLs," so
https://www.example.com/pricing/, never/pricing/. - One host and protocol. If your canonical is
https://www., do not mix inhttp://or the bare domain. Match the trailing slash style too; see canonical tags explained. - Escape special characters. An ampersand in a URL must be written
&inside the XML, or the file will not parse. - Size limits. "50MB (uncompressed) or 50,000 URLs" per file. Gzip is allowed, but the 50MB limit applies to the uncompressed size.
- Location. Google recommends the site root. Unless you submit through Search Console, a sitemap "affects only descendants of the parent directory," so
/blog/sitemap.xmlcannot cover/pricing/.
Most frameworks can generate this for you (Next.js app/sitemap.ts, the @astrojs/sitemap integration, WordPress core and SEO plugins). For a plain static site whose HTML files are committed to Git, this short script writes the file with real Git dates. Run it from the repository root:
import pathlib, subprocess, sys
from xml.sax.saxutils import escape
SITE = "https://www.example.com" # your canonical origin, no trailing slash
SRC = pathlib.Path(sys.argv[1]) # folder of built pages, e.g. dist
SKIP = {"404.html"} # pages that should never be listed
def lastmod(path):
# Date of the last commit that touched the source file, ISO 8601.
out = subprocess.run(["git", "log", "-1", "--format=%cI", "--", str(path)],
capture_output=True, text=True).stdout.strip()
return out or None
rows = []
for f in sorted(SRC.rglob("*.html")):
if f.name in SKIP:
continue
rel = f.relative_to(SRC).as_posix()
url = SITE + "/" + (rel[:-len("index.html")] if rel.endswith("index.html") else rel)
lm = lastmod(f)
rows.append(f" <url><loc>{escape(url)}</loc>" + (f"<lastmod>{lm}</lastmod>" if lm else "") + "</url>")
print('<?xml version="1.0" encoding="UTF-8"?>')
print('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
print("\n".join(rows))
print("</urlset>")
Usage: python3 make_sitemap.py public > public/sitemap.xml. Add any page you do not want listed to SKIP. If your pages are generated into a build folder that is not committed, read dates from the source files instead, since Git has no history for build output.
When do you need a sitemap index file?
Only when one file would pass 50,000 URLs or 50MB, or when you want separate files per section so Search Console reports them separately. Google's sitemap index guide sets these rules:
- An index file "may have up to 50,000
loctags," each pointing to a sitemap. - Nesting is not supported: an index cannot list another index.
- Child sitemaps must be on the same site and "in the same directory as the sitemap index file, or lower in the site hierarchy," unless you set up cross-site submission.
- You can submit up to 500 index files per site in Search Console.
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://www.example.com/sitemaps/pages.xml</loc>
</sitemap>
<sitemap>
<loc>https://www.example.com/sitemaps/blog.xml.gz</loc>
</sitemap>
</sitemapindex>
Even a small site can split by section (pages, blog, products). Search Console then lists each file on its own line, so a problem points straight at the section it came from.
How do you submit a sitemap to Google?
Use one or both of these. Each takes a couple of minutes.
- Search Console. Open your property, go to Indexing, then Sitemaps, paste the sitemap URL, and select Submit. The report then shows the last read date, status and discovered URL count.
- robots.txt. Add a line anywhere in the file:
Sitemap: https://www.example.com/sitemap.xml. Google says there is no limit on how manySitemap:lines you add, and other search engines read the same line. - Search Console API, if you manage many sites or want your deploy to resubmit automatically.
Do not bother with the old google.com/ping?sitemap= URL. Google announced its retirement in its June 2023 post, so scripts that still call it get nothing. Keep lastmod accurate instead; that is how Google now notices changes.
Also keep expectations right. Google calls a submitted sitemap "merely a hint: it doesn't guarantee that Google will download the sitemap or use the sitemap for crawling URLs on the site." A sitemap helps discovery. It does not make a page rank, or even get indexed, if Google judges the page not worth it.
How do you check a sitemap for errors?
Search Console tells you whether Google could read the file. It does not tell you, before Google crawls, which listed URLs redirect, 404, carry noindex or point their canonical elsewhere. This script does. It follows sitemap index files, reads gzipped sitemaps, and checks every URL without following redirects:
import gzip, re, sys, urllib.request, urllib.error
import xml.etree.ElementTree as ET
NS = "{http://www.sitemaps.org/schemas/sitemap/0.9}"
LASTMOD = re.compile(r"^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2}))?$")
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(self, *a, **k):
return None
opener = urllib.request.build_opener(NoRedirect)
def fetch(url):
req = urllib.request.Request(url, headers={"User-Agent": "sitemap-check/1.0"})
try:
r = opener.open(req, timeout=15)
return r.status, r.headers, r.read()
except urllib.error.HTTPError as e:
return e.code, e.headers, b""
def load(url):
status, headers, body = fetch(url)
if status != 200:
sys.exit(f"FIX sitemap {url} returned {status}")
if body[:2] == b"\x1f\x8b":
body = gzip.decompress(body)
if len(body) > 50 * 1024 * 1024:
print(f"FIX {url} is over 50MB uncompressed")
return ET.fromstring(body)
def check_page(loc, lastmod):
status, headers, body = fetch(loc)
if status in (301, 302, 307, 308):
return f"FIX {loc} redirects ({status}) to {headers.get('Location')}"
if status != 200:
return f"FIX {loc} returns {status}"
html = body.decode("utf-8", "replace")
robots = (headers.get("X-Robots-Tag") or "") + " " + " ".join(
re.findall(r'<meta[^>]+name=["\'](?:robots|googlebot)["\'][^>]*>', html, re.I))
if "noindex" in robots.lower():
return f"FIX {loc} is noindex but listed in the sitemap"
m = re.search(r'<link[^>]+rel=["\']canonical["\'][^>]*href=["\']([^"\']+)', html, re.I)
if m and m.group(1) != loc:
return f"FIX {loc} canonicalizes to {m.group(1)}"
if lastmod and not LASTMOD.match(lastmod):
return f"FIX {loc} has a malformed lastmod: {lastmod}"
return None
def main(url):
root = load(url)
if root.tag == NS + "sitemapindex":
for sm in root.iter(NS + "sitemap"):
print(f"-- child sitemap {sm.findtext(NS + 'loc').strip()}")
main(sm.findtext(NS + "loc").strip())
return
urls = list(root.iter(NS + "url"))
if len(urls) > 50000:
print(f"FIX {url} lists {len(urls)} URLs; the limit is 50,000")
seen, problems = set(), 0
for u in urls:
loc = u.findtext(NS + "loc", "").strip()
lastmod = (u.findtext(NS + "lastmod") or "").strip()
if not loc.startswith(("http://", "https://")):
print(f"FIX relative URL: {loc}"); problems += 1; continue
if loc in seen:
print(f"NOTE duplicate entry: {loc}")
seen.add(loc)
msg = check_page(loc, lastmod)
if msg:
print(msg); problems += 1
print(f"{url}: {len(urls)} URLs checked, {problems} to fix")
if __name__ == "__main__":
main(sys.argv[1])
Run it with python3 check_sitemap.py https://www.example.com/sitemap.xml. We tested it against a local site with one good page, one canonicalized duplicate, one noindexed page, one redirect, one 404 and one bad date. It printed:
FIX http://127.0.0.1:8765/b/ canonicalizes to http://127.0.0.1:8765/a/
FIX http://127.0.0.1:8765/hidden/ is noindex but listed in the sitemap
FIX http://127.0.0.1:8765/old redirects (301) to /old/
FIX http://127.0.0.1:8765/gone/ returns 404
NOTE duplicate entry: http://127.0.0.1:8765/a/
FIX http://127.0.0.1:8765/a/ has a malformed lastmod: 20/11/2026
http://127.0.0.1:8765/sitemap.xml.gz: 6 URLs checked, 5 to fix
Fix each FIX line at the source: drop the entry, or replace it with the final URL. Redirect entries are often left over from a migration; our guide to redirect chains covers cleaning those up, and fixing 404 errors covers the dead ones. The script makes one request per URL, so on a site with thousands of pages, run it on a sample or add a short delay.
If you want this cross-checked against everything else on the site, a full crawl compares sitemap entries with internal links, canonicals and status codes in one pass. The CrawlKind sample audit shows what those findings look like with evidence attached.
Sources
- Google Search Central: Build and submit a sitemap
- Google Search Central: Manage your sitemaps with sitemap index files
- Google Search Central Blog: Sitemaps ping endpoint is going away (June 2023)
- sitemaps.org: Sitemaps XML format
Frequently asked questions
Does Google use the priority tag in a sitemap?
No. Google's Build and submit a sitemap guide states that Google ignores priority and changefreq values, and its June 2023 blog post repeated that it does not use either one. Leaving them in the file causes no harm, but changing them will not change how Google crawls or ranks your pages.
Should a sitemap include pages with noindex?
No. A sitemap tells Google which URLs you want in search results, and noindex tells it the opposite. Listing a noindexed page sends conflicting signals and wastes a crawl. Remove the noindex or remove the entry, so the two always agree. A crawler that compares both will flag every mismatch.
Do I need a sitemap for a small website?
A small site that links every page from its navigation is usually found without one, but a sitemap costs almost nothing to add and helps Google find new pages sooner and report indexing problems per URL. Most frameworks and CMSs generate one automatically, so there is little reason to skip it.
How often should I update my sitemap?
Regenerate it whenever pages are added, removed or meaningfully changed, ideally as part of every deploy so it never drifts out of date. You do not need to resubmit it in Search Console after each change; Google rereads submitted sitemaps on its own and uses accurate lastmod dates to spot what changed.
Can a sitemap list URLs on another domain?
Normally a sitemap covers only URLs on its own site, and, unless submitted through Search Console, only URLs under its own directory. Google supports cross-site submission when you verify both sites in Search Console or reference the sitemap from the robots.txt of the site whose URLs it lists.
Audit your site with your AI coding agent
CrawlKind is a website audit and fix kit for Claude Code: a full crawl, a prioritized findings report, and proposed fixes you review before anything changes. $49 once.