Sub topic 6
Sitemaps as a Discovery Hint
A sitemap is a file where a site lists the URLs it wants crawled. This chapter covers the format, the limits, how crawlers use the file, and why it is a hint and not a command. It assumes you have read the earlier chapters on fetching, robots.txt, and URL discovery. You should be comfortable with HTTP status codes and with reading short Python snippets.
Why sitemaps exist
Link crawling finds pages by following links from pages already known. That has gaps:
- A new page with no inbound links is invisible until something links to it.
- Pages deep in a site may sit many clicks from the seed URLs, so they are reached late.
- Pages reachable only through forms, search boxes, or script-built navigation may never be reached.
- Large sites change constantly, and the crawler cannot tell which of millions of known URLs changed.
A sitemap addresses these by giving the crawler a direct list of URLs, optionally with modification dates. The crawler adds those URLs to its frontier alongside the ones it found through links.
A hint, not an instruction
A sitemap does not force a crawler to fetch anything. The crawler still decides, per URL, whether to fetch it, when, and whether to index the result. Several things can override a listing:
- robots.txt may disallow the URL, so the crawler never requests it.
- The crawl budget for the host may be used up by other URLs.
- The page may return an error, a redirect, or a
noindexdirective. - The page may be judged a duplicate of another URL, so the engine indexes the other one.
So a URL in the sitemap tells the engine "this exists and I care about it." It does not tell the engine "index this."
The file format
The standard format is XML. Each <url> entry has one required child, <loc>, and a few optional ones.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/guide</loc>
<lastmod>2026-01-15</lastmod>
</url>
</urlset>| Element | Required | How crawlers treat it |
|---|---|---|
| `loc` | Yes | The absolute URL, including scheme and host. Must be escaped for XML (for example `&`). |
| `lastmod` | No | The date the page content last changed, in W3C date format. Useful only if it is accurate. |
| `changefreq` | No | A hint such as `daily`. Major engines largely ignore it. |
| `priority` | No | A value from 0.0 to 1.0 relative to your own other pages. Major engines largely ignore it. |
Engines differ in what they honor, so check each engine's documentation. In practice, loc and an honest lastmod carry the value.
Keep lastmod honest
lastmod is the only optional field that helps much, and only while it stays trustworthy. If a site stamps every URL with the current time on each build, the crawler learns that the field carries no information and stops using it. Set lastmod to the time of the last meaningful content change, not the time the file was generated and not the time a footer or timestamp changed.
Size limits and sitemap index files
A single sitemap file may hold at most 50,000 URLs and must be no larger than 50 MB uncompressed. Files may be gzip-compressed, and the limit applies to the uncompressed size.
For larger sites, split the URLs across several files and list those files in a sitemap index:
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://example.com/sitemap-articles.xml</loc>
<lastmod>2026-01-15</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/sitemap-products.xml</loc>
</sitemap>
</sitemapindex>An index file can list sitemaps but not other index files, so nesting is one level deep. Splitting by content type or section also helps diagnosis later. If the products sitemap has a low indexing rate and the articles sitemap does not, you know where to look.
Other formats exist. Engines also accept RSS or Atom feeds and plain text files with one URL per line. Plain text carries no lastmod, so XML is the usual choice.
Telling crawlers where the sitemap is
There are two common ways to announce a sitemap.
- Add a
Sitemap:line to robots.txt. It takes an absolute URL, is independent of anyUser-agentgroup, and can appear more than once. - Submit the URL in the engine's webmaster tools. This also gives you reports on how the engine processed it.
User-agent: *
Disallow: /private/
Sitemap: https://example.com/sitemap-index.xmlBecause the robots.txt route needs no account with any engine, every crawler that reads robots.txt can find the file.
Scope rules
A sitemap is expected to list only URLs on its own host, and a sitemap at /blog/sitemap.xml may only list URLs under /blog/. Placing the file at the site root avoids the problem. Listing URLs for another host is accepted only when that host proves it agrees, usually by referencing the sitemap in its own robots.txt.
Reading a sitemap in code
Here is a small parser that handles both file types. It uses the standard library and a namespace map, because the sitemap elements live in the sitemaps.org XML namespace. A parser that ignores the namespace finds nothing.
import xml.etree.ElementTree as ET
NS = {"sm": "http://www.sitemaps.org/schemas/sitemap/0.9"}
def parse_sitemap(xml_text):
root = ET.fromstring(xml_text)
kind = root.tag.split("}")[-1]
if kind == "sitemapindex":
locs = [e.findtext("sm:loc", default="", namespaces=NS).strip()
for e in root.findall("sm:sitemap", NS)]
return "index", [loc for loc in locs if loc]
entries = []
for e in root.findall("sm:url", NS):
loc = e.findtext("sm:loc", default="", namespaces=NS).strip()
lastmod = e.findtext("sm:lastmod", namespaces=NS)
if loc:
entries.append((loc, lastmod))
return "urlset", entries
urlset = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://example.com/guide</loc><lastmod>2026-01-15</lastmod></url>
<url><loc>https://example.com/about</loc></url>
</urlset>"""
index = """<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>https://example.com/sitemap-articles.xml</loc></sitemap>
<sitemap><loc>https://example.com/sitemap-products.xml</loc></sitemap>
</sitemapindex>"""
print(parse_sitemap(urlset))
print(parse_sitemap(index))This prints:
('urlset', [('https://example.com/guide', '2026-01-15'), ('https://example.com/about', None)])
('index', ['https://example.com/sitemap-articles.xml', 'https://example.com/sitemap-products.xml'])A real crawler would fetch each file over HTTP, decompress .gz files, recurse into the child sitemaps from an index, and feed each loc through the same normalization and robots.txt checks as any link it discovered.
How crawlers use the data
After reading a sitemap, the crawler treats each entry as a candidate URL. Typical handling:
- Normalization. The URL is cleaned the same way as a discovered link, so fragments and obvious variants collapse.
- Permission check. The URL is tested against robots.txt before any fetch.
- Prioritization. A new URL, or one with a
lastmodlater than the last crawl, may be ranked higher in the frontier. An unchangedlastmodsupports skipping a refetch. - Trust tracking. The engine compares
lastmodclaims against what it sees on fetch. Repeated mismatches reduce how much weight it gives your file.
Sitemaps are most valuable for new sites, very large sites, sites with weak internal linking, and sites that publish fresh content often. A small, well-linked site often gains little from one, though it does no harm.
What belongs in a sitemap
List the URLs you want to appear in search results. Each should be the canonical version of its page, return a 200 status, and be allowed by robots.txt and free of noindex.
Leaving out the following keeps the signals consistent:
- Redirecting URLs and URLs that return 404 or 5xx errors.
- Non-canonical duplicates, such as parameter variants or the
httpversion of anhttpspage. - Pages blocked by robots.txt or marked
noindex. - Internal search results and endless filter combinations.
A sitemap that lists a noindex page says "index this" and "do not index this" at once. Engines usually obey the page-level directive, but you waste crawl effort and muddy your diagnostics.
Common errors
- Wrong namespace or missing declaration. Parsers may reject the file or read zero entries.
- Relative URLs in
loc. The value must be absolute. - Unescaped characters. An
&in a query string must be written&. - Exceeding limits. Files over 50,000 URLs or 50 MB are rejected or truncated.
- Stale files. A cached sitemap that never updates hides new pages and keeps dead URLs listed.
- Sitemap blocked by robots.txt. The sitemap file itself must be fetchable.
- Mixed hosts or protocols. Listing
httpURLs on anhttpssite, or awwwvariant of the host, produces non-canonical entries.
When a listed page is not indexed, the sitemap report in the engine's tools usually shows whether the file was read, how many URLs it found, and which ones had errors. Check there first, then move on to the page-level causes covered in the diagnosis chapter.
Exercise
A site has 120,000 product pages and publishes one sitemap file with all of them. Its robots.txt disallows /products/archive/, but 4,000 URLs under that path are in the sitemap. Name two problems and how to fix each.
Show answer
First, the file exceeds the 50,000 URL limit per sitemap, so it may be rejected or truncated. Split the URLs into several files and list them in a sitemap index (at least three files). Second, the 4,000 archive URLs are blocked by robots.txt, so a compliant crawler will not fetch them, and listing them sends conflicting signals. Remove them from the sitemap, or remove the Disallow rule if they should be crawled. If they should be crawled but not indexed, allow crawling and use noindex.