For almost 30 years robots.txt worked from a 1994 convention and each crawler’s reading of it. In September 2022 it became a standard: RFC 9309, the Robots Exclusion Protocol. The RFC is short, and most of it settles questions crawlers used to answer differently: which group applies, which rule wins, how big a file must be read, and what to do when the file cannot be fetched.
Key takeaways
- A crawler obeys the group whose user-agent line matches its product token, case-insensitively. If one matches, the
*group is ignored. - Within the group, the most specific rule wins: the one with the most octets. On a tie,
Allowwins. - Crawlers must parse at least 500 KiB and should not use a cached copy older than 24 hours, unless the file is unreachable.
- A 4xx means “no rules”; a 5xx or network failure means “assume everything is disallowed”.
- The RFC says the rules “are not a form of access authorization”. They express the site’s wishes, not permission.
Groups: which rules apply to you
A robots.txt file is a list of groups. Each group starts with one or more User-agent lines and continues with Allow and Disallow rules. A crawler picks the group whose user-agent value matches its product token, the short name it announces, such as ExampleCollector. Matching is case-insensitive. If several groups name the same token, their rules are combined. If none does, the crawler uses the * group. If there is no * group either, no rules apply.
The detail people miss: a matching named group replaces the * group rather than adding to it. In the example below, a crawler called ExampleCollector is bound only by Disallow: /search. Everything in the * group, including the cart rule, does not apply to it. If a site wants a rule to apply to everyone, it has to repeat it in each named group.
User-agent: *
Disallow: /cart
Allow: /cart/help
Disallow: /*?sort=
Allow: /products/
Disallow: /products/*.json$
User-agent: ExampleCollector
Disallow: /search The RFC also says the product token should be a substring of the crawler’s identification string (its User-Agent header), may contain only letters, underscores and hyphens, and that the identification string should describe the crawler’s purpose. That is a requirement worth meeting: a site cannot write a rule for a crawler it cannot name.
Matching: the longest rule wins
Within the chosen group, every Allow and Disallow rule is compared with the URL path. Rules match from the start of the path. Two special characters exist: * matches any sequence of characters and $ anchors the end. Section 2.2.2 then settles conflicts: the most specific match, meaning the rule with the most octets, must be used. If an allow and a disallow rule are equally specific, allow should be used. Matching is case-sensitive, so /Cart and /cart are different paths. The file /robots.txt itself is always allowed.
The longest matching rule decides
Rules that match each URL in the example file, sized by length; the winning rule is colored
The second trace is the one that surprises people. Disallow: /*?sort= looks like a rule against every sorted URL, but Allow: /products/ is two octets longer, so sorted product listings are allowed. Length beats intent. When you write rules, check them with a matcher, not by reading.
Limits and caching
- Size. Crawlers must parse at least the first 500 kibibytes. Rules beyond whatever limit a crawler applies may be ignored. Google documents the same 500 KiB limit.
- Caching. Crawlers should not use a cached copy for more than 24 hours, unless the file is unreachable. Standard HTTP cache control may shorten that. Google says it generally caches for up to 24 hours.
- Redirects. Crawlers should follow at least five consecutive redirects, even across hosts, before giving up.
- Scope. A robots.txt file applies to the protocol, host and port it is served from.
shop.example.comandwww.example.comeach need their own.
When the file can’t be fetched
Error handling is where the RFC is most consequential. If robots.txt returns a 4xx status, the file is “unavailable” and the crawler may access any resource. If the server returns a 5xx or cannot be reached, the file is “unreachable” and the crawler must assume complete disallow. If that lasts a long time, about 30 days in the RFC’s example, the crawler may treat the file as unavailable or keep using a cached copy. Google’s documented behavior follows the same logic with its own timings, and treats 429 like a server error rather than a 4xx.
When robots.txt can't be fetched, the standard and Google differ
What each source says to do for each fetch outcome
For a data collector the safe reading is the RFC’s: if you cannot read robots.txt because the server is failing, do not crawl. A server that cannot serve a small text file is not a server to send product-page traffic to.
A minimal matcher you can test
The function below implements group selection and longest-match precedence as described above. It is deliberately small. A production parser also needs percent-encoding normalization, which the RFC specifies, and a size cap on input.
Pythonimport re
def parse(text):
groups, cur, in_rules = [], None, False
for raw in text.splitlines():
line = raw.split("#", 1)[0].strip()
if ":" not in line:
continue
key, val = (p.strip() for p in line.split(":", 1))
key = key.lower()
if key == "user-agent":
if cur is None or in_rules: # a new group starts
cur = ([], []); groups.append(cur); in_rules = False
cur[0].append(val.lower())
elif key in ("allow", "disallow") and cur is not None:
in_rules = True
if val: # empty Disallow = no rule
cur[1].append((key == "allow", val))
return groups
def rules_for(groups, token):
token = token.lower()
named = [r for agents, rules in groups if token in agents for r in rules]
return named or [r for agents, rules in groups if "*" in agents for r in rules]
def allowed(rules, path):
if path == "/robots.txt":
return True
best = None
for allow, rule in rules:
end = rule.endswith("$")
pattern = re.escape(rule.rstrip("$")).replace(r"\*", ".*") + ("$" if end else "")
if re.match(pattern, path):
key = (len(rule.encode()), allow) # most octets, then allow
best = max(best, key) if best else key
return True if best is None else best[1] The traces in the figure above were produced with this logic. Feed it the robots.txt of a site you plan to collect from, with your own product token, before the first request goes out.
What RFC 9309 leaves out
The RFC defines User-agent, Allow and Disallow, and lets crawlers interpret other records such as Sitemap. It does not define Crawl-delay, rate limits, or anything about how data may be used once fetched. And section 1 is explicit that the rules “are not a form of access authorization”. Whether a site’s robots.txt has legal weight is a separate question, and the answer depends on the jurisdiction and the facts. For the US picture, see is web scraping legal in the US.
How we use robots.txt
We read and obey the robots.txt of every site we collect from, for the product token our collectors announce. When a site disallows the paths a client needs, we look for an official feed or API, or we tell the client the source is not available.
Quick answers
What is RFC 9309?
RFC 9309 is the Robots Exclusion Protocol standard, published by the IETF in September 2022. It specifies how robots.txt groups, Allow and Disallow rules, matching, caching and error handling work.
Which rule wins when Allow and Disallow both match?
The most specific one, meaning the rule with the most octets. If an Allow and a Disallow rule are equally long, the RFC says Allow should be used.
Does the * group apply if my crawler has its own group?
No. If a group names your crawler’s product token, you follow that group. The rules in the * group are not added to it.
What should a crawler do if robots.txt returns 503?
Under RFC 9309 a server error means the file is unreachable, and the crawler must assume complete disallow until it can fetch the file again.
Is robots.txt legally binding?
RFC 9309 states that the rules are not a form of access authorization. Legal effect depends on jurisdiction and circumstances, so treat robots.txt as the site’s stated wishes and obey it.
Data collected within the site’s rules
Our collectors check robots.txt before every crawl and stop when a path is disallowed. See how we work or ask about a source.
