Two small text files decide what search engines can see of your site: robots.txt and the XML sitemap. Both break quietly. A staging Disallow: / ships to production, a CMS plugin writes sitemap URLs on the wrong host, a migration leaves robots.txt answering 500. Visitors see nothing, so nobody notices until traffic drops.
Here are the failures worth checking, and how to check them with curl or a short Python script.
What actually goes wrong
In robots.txt
-
The HTTP status matters more than the content. A 404 means "no rules, crawl everything". A 5xx is different: on a server error Google stops crawling the site for the first 12 hours, then uses the last good copy for up to 30 days (Google's robots.txt documentation). A broken
robots.txtis worse than a missing one. -
Disallow: /underUser-agent: *blocks the whole site for every crawler that follows the file. It is the classic leftover from a staging server. -
Blocking is not de-indexing. A blocked URL can still appear in results if other sites link to it, and the crawler never sees a
noindextag on a page it may not fetch. To remove a page from results, allow crawling and usenoindex. -
Sitemap:must be a full URL. Google's documentation asks for a fully qualified URL;Sitemap: /sitemap.xmlmay simply be ignored.
In sitemaps (sitemaps.org protocol)
- At most 50,000 URLs and 50 MB (uncompressed) per file; bigger sites need a sitemap index.
-
<lastmod>must be a W3C date (2026-11-30or2026-11-30T10:00:00+00:00). "30/11/2026" is not. - URLs must be on the same host as the sitemap.
https://example.com/sitemap.xmllistinghttps://www.example.com/...URLs is the common case: search engines can ignore those entries. - Duplicate
<loc>entries and URLs that return 404 add noise: the sitemap is supposed to list the pages you want crawled.
Option A: curl for one site
curl -s -o /dev/null -w "%{http_code}\n" https://github.com/robots.txt
curl -s https://github.com/robots.txt | grep -i -E "^(user-agent|disallow: /$|sitemap)"
curl -s https://github.com/sitemap_marketing.xml | grep -c "<loc>"
Status, groups and declared sitemaps, then the entry count. Fine for one site, tedious for twenty.
Option B: a Python script for a list
Standard library only. It follows declared sitemaps (or tries /sitemap.xml), gzip and index files, and checks the rules above.
import gzip, re, sys, urllib.request, urllib.error
import xml.etree.ElementTree as ET
from urllib.parse import urljoin, urlparse
NS = "{http://www.sitemaps.org/schemas/sitemap/0.9}"
W3C = re.compile(r"^\d{4}(-\d{2}(-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2}))?)?)?$")
def get(url):
req = urllib.request.Request(url, headers={"User-Agent": "crawl-check"})
try:
with urllib.request.urlopen(req, timeout=20) as r:
return r.status, r.read(5_000_000)
except urllib.error.HTTPError as e:
return e.code, b""
def check_sitemap(url, host, todo):
status, body = get(url)
if status != 200:
return print(f" {url}: status {status}")
if body[:2] == b"\x1f\x8b":
body = gzip.decompress(body)
if b"<!DOCTYPE" in body or b"<!ENTITY" in body:
return print(f" {url}: has a DOCTYPE, skipped")
try:
root = ET.fromstring(body)
except ET.ParseError as e:
return print(f" {url}: invalid XML ({e})")
locs = [l.text.strip() for l in root.iter(NS + "loc") if l.text]
kind = root.tag.replace(NS, "")
print(f" {url}: {kind}, {len(locs)} entries")
if kind == "sitemapindex":
todo.extend(locs)
return
if len(locs) > 50_000:
print(" more than 50,000 URLs in one file")
if len(set(locs)) < len(locs):
print(f" {len(locs) - len(set(locs))} duplicate <loc>")
foreign = [l for l in locs if urlparse(l).hostname != host]
if foreign:
print(f" {len(foreign)} URLs on another host, e.g. {foreign[0]}")
bad = [m.text for m in root.iter(NS + "lastmod") if not W3C.match((m.text or "").strip())]
if bad:
print(f" {len(bad)} <lastmod> not in W3C format, e.g. {bad[0]!r}")
def check(site):
base = site if "://" in site else "https://" + site
host = urlparse(base).hostname
status, body = get(urljoin(base, "/robots.txt"))
print(f"{base}/robots.txt -> {status}")
agent, sitemaps = None, []
for line in body.decode("utf-8", "replace").splitlines():
key, _, value = line.split("#")[0].partition(":")
key, value = key.strip().lower(), value.strip()
if key == "user-agent":
agent = value
elif key == "disallow" and agent == "*" and value == "/":
print(" Disallow: / for User-agent: * (whole site blocked)")
elif key == "sitemap":
sitemaps.append(value)
if not sitemaps:
print(" no Sitemap line, trying /sitemap.xml")
sitemaps = [urljoin(base, "/sitemap.xml")]
todo, done = list(sitemaps), 0
while todo and done < 10: # an index can point to thousands of files
check_sitemap(todo.pop(0), host, todo)
done += 1
for line in open(sys.argv[1], encoding="utf-8"):
if line.strip():
check(line.strip())
Run it with python check_crawl.py sites.txt. Output from a real run on four sites (the dev.to part is cut after two files):
https://example.com/robots.txt -> 404
no Sitemap line, trying /sitemap.xml
https://example.com/sitemap.xml: status 404
https://github.com/robots.txt -> 200
https://github.com/sitemap_marketing.xml: urlset, 376 entries
1 duplicate <loc>
https://www.python.org/robots.txt -> 200
no Sitemap line, trying /sitemap.xml
https://www.python.org/sitemap.xml: status 404
https://dev.to/robots.txt -> 200
https://dev.to/sitemap-index.xml: sitemapindex, 253 entries
https://dev.to/sitemap-posts-0.xml: urlset, 750 entries
...
Read it with judgement: a site without a sitemap is not broken (python.org is crawled fine), it just gives search engines less help. The dev.to index lists 253 files and the script stops after 10, which is the right trade-off for a quick check.
Limits of this script: it only remembers the last User-agent line, so a group with several User-agent lines is parsed loosely; it does not report unknown directives or relative Sitemap: URLs; it does not test whether sitemap URLs are alive; and it does not refuse private addresses, so do not feed it URLs from untrusted users.
Option C: a hosted checker
Disclosure: this one is ours. We publish Robots.txt & Sitemap Checker on Apify. It runs these checks on a list of sites, adds what the script skips (rules placed before any User-agent, unknown directives, paths not starting with /, relative Sitemap: URLs, entries with no <loc>), requests 0 to 3 sample URLs from each sitemap file and reports any status of 400 or above, and refuses hosts that resolve to private or local addresses, also after a redirect.
{
"urls": ["github.com", "example.com", "https://www.python.org"],
"sampleUrls": 3
}
On a real run, github.com returns robotsStatus: 200, its declared sitemap with 376 entries and the problem 1 duplicate <loc> values. example.com returns robots.txt returns 404: crawlers treat the site as fully crawlable, no Sitemap line in robots.txt (tried /sitemap.xml) and https://example.com/sitemap.xml: returns 404.
It is free during launch: no per-site fee at the moment, only Apify's platform usage, which the Free plan's monthly credit covers for normal use.
Its limits, stated plainly:
- It validates the files, it does not apply your rules: it will not tell you whether a given URL is allowed for a given crawler, and wildcard and precedence rules are not evaluated.
- Only the root
/robots.txtis read; subdomains are separate inputs. - Sitemaps are read up to 5 MB after decompression (a larger file is reported as not validated), and index files are followed for up to 10 files per site.
- The dead-link check is a smoke test of at most 3 URLs per file. Image, video and news sitemap extensions are not validated.
- Sites that block automated clients are reported with their HTTP status. Only check sites you are allowed to look at.
A short routine
- After every deploy, check that
robots.txtreturns 200 (or a deliberate 404) and has noDisallow: /for*. - Once a month, check the sitemap host, the entry count and a few sample URLs.
Top comments (0)