robots.txt is a text file websites publish at the top level of each host (e.g., example.com/robots.txt) that tells search engine crawlers and other bots which paths they may or may not access. It's voluntary: well-behaved crawlers respect it, but it has no technical enforcement mechanism of its own.
The format is the Robots Exclusion Protocol, published as RFC 9309 in September 2022. Crawlers must follow the rules in a file they have downloaded, but those rules are not a form of access authorization. This entry covers how the file is structured, how crawlers settle conflicting rules, what happens when the file can't be fetched, and what it doesn't do.
How a robots.txt File Works
Rules are grouped by crawler. Each group starts with one or more user-agent lines naming a crawler, followed by allow and disallow lines with URL paths. Crawlers match their name case-insensitively, and if no group names them, they follow the user-agent: * group if there is one. This lets a site give one search engine broad access while blocking others.
user-agent: *
disallow: /cart
allow: /cart/help
user-agent: ExampleBot
disallow: /
Google supports four fields: user-agent, allow, disallow, and sitemap. Other fields, such as crawl-delay, aren't supported by Google, so they can't be used to slow Googlebot down.
How Crawlers Settle Conflicting Rules
- Longest match wins: When an allow rule and a disallow rule both match a URL, the one with the most characters applies. In the example above,
/cart/helpstays open even though/cartis blocked. - Ties go to allow: If the two rules are equivalent, the allow rule should be used.
- Wildcards:
*matches zero or more of any character, and$marks the end of a pattern, sodisallow: /*.pdf$blocks URLs ending in.pdf.
What Happens When robots.txt Can't Be Fetched
A crawler's behavior depends on the response it gets for the file itself, and the outcomes are opposite. A missing file opens the whole site; a server error closes it.
| Situation | RFC 9309 | |
|---|---|---|
| 4xx response (e.g., 404) | The crawler may access any resource | Treated as if no robots.txt exists, except 429 |
| 5xx response or unreachable | The crawler must assume complete disallow | 5xx follows its own timed retry process; DNS and network failures count as server errors |
| Caching | A cached copy shouldn't be used for more than 24 hours, unless the file is unreachable | Generally cached up to 24 hours, longer if it can't be refreshed |
| File size | Parsers must handle at least 500 KiB | Content after 500 KiB is ignored |
This matters on both sides. A site whose robots.txt briefly returns errors can lock out compliant crawlers, and a rule change can take up to a day to reach them. A crawler that treats a failed fetch as "no rules" breaks the protocol.
What robots.txt Doesn't Do
- Keep pages out of search: Google says robots.txt is not a mechanism for keeping a page out of Google. A blocked URL can still be indexed without being crawled if other pages link to it. To keep a page out, use
noindexor password protection, and leave the page crawlable so thenoindexcan be seen. - Secure anything: The file is public, so listing private paths in it shows attackers where they are. Malware robots and email address harvesters ignore it.
- Bind every bot: Compliance is voluntary, so sensitive content needs real access controls.
What It Means for Web Scraping
Before crawling, fetch the robots.txt at the root of each host, since each subdomain has its own file. Find the group for your crawler's user-agent, fall back to *, and apply the longest-match rule to every URL you plan to request. Many sites now add groups that target AI crawlers by name, so a file that allowed your bot last month may not today.
Re-fetch the file at least once a day, and treat a 5xx or a timeout as "disallow everything" until it loads. Because robots.txt is mainly a tool for managing crawler traffic, pair it with request throttling even where crawl-delay isn't set. Routing requests through proxies doesn't change what the file permits: its rules apply to the crawler, not to the IP address it connects from.