opyeb robotslab

robotslab · Basics

robots.txt structure and the order it is read

User-agent groups, Allow and Disallow, Sitemap, 404 and 5xx

robots.txt is a single text file at the root of a host, /robots.txt. It is the first thing a crawler requests when it starts collecting, and its rules decide which paths may be fetched. The syntax is small, but a wrong idea about how groups are formed or what a status code means makes the file do the opposite of what was intended.

The shape of the file

Lines take the form directive: value. Spaces around the colon are ignored and everything after # is a comment. Directive names are case-insensitive, but path values are not: Disallow: /Admin/ does not block /admin/.

User-agent: * Disallow: /admin/ Disallow: /search? Sitemap: https://example.com/sitemap.xml

The order a crawler reads

A crawler looks for the group whose product token matches its own and applies only that group's rules. When several groups match, the group with the longest token is chosen, and the * group is used only when nothing else matches. If the same token appears in more than one group, crawlers merge those groups.

  1. Request /robots.txt from the host of the URL to be collected. Redirects are followed up to five times.
  2. On a 2xx response, parse the body. On 404 or 410, treat the site as having no rules and allow everything.
  3. On a 5xx error or 429, most crawlers treat the site as temporarily blocked and stop collecting for at least a day.
  4. Decide the path with the rules of the matched group. If no rule matches, the path is allowed.

A robots.txt that returns a 500 is the same as blocking the whole site. If a CDN or proxy answers with an empty 200 during an outage, the rules disappear and every path opens. Check how your deployment actually serves this file.

How groups are formed

Consecutive User-agent lines belong to one group, and the Allow and Disallow lines below them are that group's rules. A new User-agent line after a rule starts a new group.

File contentReading
User-agent: A
User-agent: B
Disallow: /x
One group blocking /x for both A and B
User-agent: A
Disallow: /x
User-agent: B
Disallow: /y
Two groups: A blocks /x, B blocks /y
Disallow: /xA rule outside any group, so it applies to no crawler

The usual mistakes

Paste the file into this page and the groups, the rules in each one and the crawler each rule reaches are visible at once, together with line numbers for problems such as a missing colon or an out-of-order group.

Questions

Do all crawlers obey robots.txt?

No. It is a convention followed voluntarily, and malicious collectors ignore it. Sensitive paths need authentication and access control.

What happens when the file is missing?

A 404 is read as having no rules, so every path is allowed. A 5xx, by contrast, can be read as a block.

Can a robots.txt live in a subdirectory?

No. Crawlers read only <code>/robots.txt</code> at the host root and ignore one placed deeper.

See how the groups and rules of your file are actually read.

Open the tool

This article follows RFC 9309 (Robots Exclusion Protocol, September 2022), the robots.txt internet draft (September 2022) and the llmstxt.org proposal (September 2024). Every domain and rule shown is synthetic.