Sub topic 6
Sitemaps as a Discovery Hint
This chapter assumes you know how crawlers extract links from HTML and normalize URLs. It also assumes you can read short Python snippets. Here you will see what a sitemap is, what it can and cannot do, and the errors that make a sitemap useless.
What a sitemap is
A sitemap is an XML file that lists URLs a site owner wants crawled. Link-following finds pages only if some already-known page links to them. A sitemap gives the crawler a second source of URLs. This helps with new pages, deep pages, and pages with few internal links.
Here is a minimal sitemap:
<?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>Each <url> entry needs a <loc> with the full absolute URL. The <lastmod> element is optional. It tells the crawler when the page last changed, which can help it decide whether to fetch the page again.
How crawlers find a sitemap
A crawler learns about a sitemap in one of two ways. You can add a Sitemap: line to robots.txt, as in Sitemap: https://example.com/sitemap.xml. You can also submit the file through a search engine's webmaster tool. The Sitemap: line is not tied to any User-agent group, so every crawler can read it.
A hint, not a command
A sitemap only suggests URLs. Listing a URL does not guarantee that it is crawled, and a crawled page is not guaranteed to be indexed. The URL still goes into the crawl frontier and competes with other URLs. The crawler still obeys robots.txt, crawl rate limits, and canonicalization. Leaving a URL out of the sitemap does not block it either. The crawler can still find it through links.
Limits and structure
A single sitemap file may hold up to 50,000 URLs and must be no larger than 50 MB uncompressed. Larger sites split their URLs across several files. They then list those files in a sitemap index, which uses <sitemapindex> and <sitemap> elements in place of <urlset> and <url>.
Common errors
- Relative or non-canonical URLs. Every
<loc>should be an absolute URL, and it should be the canonical version of the page. Listing duplicates wastes crawl budget and sends mixed signals. - Blocked URLs. If
robots.txtdisallows a listed URL, the crawler will not fetch it. - Noindex or redirecting URLs. A sitemap should list only pages that return
200and that you want indexed. - A wrong host. A sitemap generally should list only URLs on its own host and protocol. Mixing
httpandhttps, orwwwand non-www, leads to ignored entries. - A stale
lastmod. If every page always shows today's date, the crawler learns that the value is unreliable and may ignore it. - Malformed XML. Unescaped characters such as
&in a URL make the whole file fail to parse. Write&instead.
Exercise
A site's sitemap lists /old-page, which returns a 301 redirect to /new-page. Which entry should the sitemap contain, and why?
Show answer
It should list /new-page. A sitemap should contain the final canonical URL that returns 200. Listing the redirecting URL wastes crawl budget and gives the crawler an extra hop to resolve.
Exercise
You add a URL to your sitemap, but robots.txt disallows it. Will the crawler fetch it?
Show answer
No. The sitemap only suggests the URL. The crawler still checks robots.txt before fetching, and the Disallow rule prevents the fetch.