Sub topic 3
robots.txt: the standard everything else is compared to
This chapter assumes you know how a website is served over HTTP, can read a simple access log, and have a general idea of what AI assistants are. It explains how robots.txt works, because every newer proposal in this tutorial is measured against it. By the end you should be able to write correct rules, predict how a compliant crawler reads them, and say what robots.txt cannot do.
What robots.txt is
robots.txt is a plain text file served at the root of a host, for example https://example.com/robots.txt. It tells automated clients (crawlers) which URL paths they are asked not to fetch. It has been in use since 1994. In 2022 it was published as the Robots Exclusion Protocol, RFC 9309.
Three facts shape everything else in this chapter:
- The file is per host.
example.com,www.example.comanddocs.example.comeach need their own file. The protocol and port are part of the host identity too. - The file is advisory. Nothing in HTTP stops a client from ignoring it. A crawler honors it because its operator chose to.
- The file controls fetching, not use. It says "do not request this path". It does not say what may be done with content that was already collected.
The file format
A robots.txt file is a list of groups. Each group starts with one or more User-agent lines and is followed by rules.
| Directive | Meaning |
|---|---|
| `User-agent` | The crawler token the group applies to. `*` matches any crawler not matched by a more specific group. |
| `Disallow` | A path prefix the crawler should not fetch. An empty value disallows nothing. |
| `Allow` | A path prefix the crawler may fetch. Used to carve exceptions out of a `Disallow`. |
| `Sitemap` | The absolute URL of a sitemap. It is not tied to any group. |
Here is the example from the topic plan. It asks three AI-related agents to stay out and leaves everyone else unrestricted.
User-agent: GPTBot
Disallow: /
User-agent: Google-Extended
Disallow: /
User-agent: CCBot
Disallow: /
User-agent: *
Allow: /
Sitemap: https://example.com/sitemap.xmlRules for matching
RFC 9309 defines how a crawler picks a group and a rule. These details cause most real mistakes.
- Token matching ignores case.
GPTBotandgptbotare the same token. - The most specific group wins, and groups are not merged. A crawler uses the group whose
User-agentmatches it best. If it finds one, it ignores the*group completely. A named group that lists onlyDisallow: /private/does not inherit anything from*. - The longest matching path wins. If both
AllowandDisallowmatch a URL, the rule with the longer path decides. If the lengths are equal,Allowwins. - Paths are prefixes.
Disallow: /docsblocks/docs,/docs/, and also/docs-archive. Add a trailing slash to limit it to a directory. - Wildcards are limited.
*matches any run of characters and$anchors the end of the URL. Other regular expression syntax is not supported. - Unknown lines are ignored. This is how extensions such as
Crawl-delayorContent-Signalcan sit in the file without breaking parsers that do not know them. A crawler that does not know a directive simply skips it.
A common error follows from rule 2. Suppose you write this:
User-agent: *
Disallow: /private/
User-agent: GPTBot
Disallow: /drafts/GPTBot reads only its own group. It is told to avoid /drafts/ and has no restriction on /private/. To block both paths for GPTBot, repeat the /private/ rule in its group.
Checking rules with code
You do not have to guess how a compliant crawler reads your file. Python's standard library includes a parser. This example refuses GPTBot and lets other agents fall back to the wildcard group.
from urllib.robotparser import RobotFileParser
rules = """User-agent: GPTBot
Disallow: /
User-agent: *
Allow: /
""".splitlines()
rp = RobotFileParser()
rp.parse(rules)
for agent in ["GPTBot", "CCBot", "Googlebot"]:
print(agent, rp.can_fetch(agent, "https://example.com/docs/"))The output is:
GPTBot False
CCBot True
Googlebot TrueCCBot and Googlebot have no group of their own here, so they use *, which allows everything. If you had also listed CCBot in the file, as in the earlier example, it would be refused.
The standard library parser is a convenient approximation. It differs from RFC 9309 in some edge cases, such as how it orders Allow and Disallow rules, so treat a real crawler's own documentation as the final word for that crawler.
How crawlers fetch and cache the file
Crawlers request /robots.txt before they crawl other URLs on a host, and they cache the result. The HTTP status of that request changes how they behave.
| Response to `/robots.txt` | What RFC 9309 says a crawler should do |
|---|---|
| 200 with a file | Parse it and follow the rules. |
| 4xx, such as 404 | Treat it as "no restrictions" and crawl freely. |
| 5xx or network failure | Treat the site as fully disallowed for a while. Many crawlers stop crawling until it recovers. |
| Redirects | Follow a limited number of them, five in the RFC. |
Two consequences matter in practice. A site that returns a server error for /robots.txt can disappear from crawls unexpectedly. And a file that is cached for up to 24 hours (the RFC's suggested ceiling, unless it cannot be refreshed) means your edits do not take effect instantly. After a change, expect a delay before a crawler's behavior changes.
The RFC also says crawlers may limit how much of the file they read, with a minimum of 500 kibibytes. Keep the file small and put the important rules near the top.
What robots.txt does not do
Understanding the limits is the reason this file is the baseline for the rest of the tutorial.
- It does not enforce anything. A crawler that ignores the file can fetch every URL. Chapter material on enforcement covers what to use when that is not acceptable.
- It does not remove content from search results. A URL blocked by robots.txt can still be listed if other pages link to it, because the crawler never fetches the page to see a
noindexinstruction. Blocking a page also stops crawlers from reading anoindextag on it. Meta and header directives are the tool for index control. - It does not hide anything. The file is public. Listing
/secret-admin/in it advertises that the path exists. - It does not express purpose. The protocol has no standard way to say "you may index this for search but not use it for training". The only lever is the user-agent token, which is why the next chapter looks at how AI operators split their crawlers by purpose.
- It does not cover content already collected. Adding a rule today does not remove pages that were fetched last year.
- It does not authenticate the crawler. The
User-agentheader is a string the client chooses. Anyone can sendGPTBotin a request.
Why it matters for AI
robots.txt is the one mechanism that major AI operators say they honor. That is why the sample file at the top of this chapter names AI tokens. Several things follow:
- Rules are written per token, so you need to know which token belongs to which purpose. A rule for one token does not affect another operator's crawler or even a second crawler from the same operator.
- Some AI-related tokens are not crawlers at all.
Google-Extended, for example, is a control token. Google fetches pages with its normal crawler and uses the token to decide whether the content may be used for certain AI purposes. Blocking it does not change what shows in your server log, since no separate bot visits. - Compliance is voluntary and varies. Operators publish what they honor, and independent reports have described crawlers that did not follow the rules. Verify behavior in your logs instead of assuming it.
Practical guidance
- Keep the file at
/robots.txt, served withContent-Type: text/plain, over the same protocol and host as the pages it governs. - Put a
User-agent: *group last or anywhere; order between groups does not matter, but specific groups do override it. - Add a
Sitemap:line. It is the easiest cross-reference to the sitemap discussion later in the tutorial. - Test every change with a parser before publishing, then watch your logs for the crawlers you targeted.
- Document why each block exists. Months later, nobody remembers why
CCBotwas disallowed.
Exercise
A robots.txt contains the group "User-agent: *" with "Disallow: /private/", and a second group "User-agent: ClaudeBot" with "Disallow: /drafts/". Can ClaudeBot fetch /private/report.html, and why?
Show answer
Yes. ClaudeBot matches its own named group, so it ignores the "*" group entirely. Groups are not merged, and its group only disallows /drafts/. To block /private/ for ClaudeBot too, repeat "Disallow: /private/" inside the ClaudeBot group.
Exercise
Your site returns HTTP 503 for /robots.txt during a deployment that lasts several hours. What do compliant crawlers typically do, and what is the risk?
Show answer
They treat a server error as "assume everything is disallowed" and pause crawling until the file can be fetched again. The risk is a drop in crawling, and possibly in freshness of indexed content, caused by an unrelated outage. Serve a valid robots.txt (or at least a 404 if you intend no restrictions) even while other parts of the site are down.
Exercise
You want a page kept out of search results. Is "Disallow: /page.html" in robots.txt enough?
Show answer
No. It only asks crawlers not to fetch the page. The URL can still appear in results if other sites link to it. Allow crawling and add a noindex meta tag or X-Robots-Tag header, or require authentication, depending on the goal.