Sub topic 7
Groups, Allow, Disallow, and How robots.txt Rules Are Matched
This chapter assumes you understand HTTP requests, the User-Agent header, web crawlers, and how to edit a site's root-level robots.txt file. The focus here is rule matching: how a crawler chooses a group and how it decides whether a URL is allowed.
The structure of a robots.txt file
A robots.txt file contains groups. Each group starts with one or more User-agent lines and continues with Allow or Disallow rules.
User-agent: GPTBot
Disallow: /private/
Allow: /private/public-report.html
User-agent: *
Disallow: /admin/The first group applies to GPTBot. The second group is a fallback for crawlers that do not have a more specific group. A crawler does not combine the first group with the wildcard group. It selects the most specific matching group.
A User-agent value identifies a crawler product. Matching is case-insensitive. A crawler whose product token is GPTBot matches User-agent: GPTBot. A crawler named ExampleBot does not match that group, but it does match User-agent: *.
How a group is selected
Use a specific group when one crawler needs a different policy from the rest of the crawlers.
User-agent: OAI-SearchBot
Allow: /
User-agent: *
Disallow: /OAI-SearchBot receives the specific group and can fetch the site. Other crawlers receive the wildcard group and are blocked.
If you write several User-agent lines together, they are aliases for the same rule set:
User-agent: GPTBot
User-agent: ClaudeBot
Disallow: /members/Both crawlers receive the same restriction. Keep the rules together only when the policy is genuinely identical. Separate groups make later policy changes easier to review.
How Allow and Disallow are matched
A rule normally matches the URL path from the host onward. A rule such as Disallow: /drafts/ matches paths beginning with /drafts/, including /drafts/old-plan.html. It does not match /public/drafts/ because that path does not begin with /drafts/.
The most specific matching rule wins. Specificity is measured by the matching path length. If an Allow and a Disallow rule match the same URL with equal length, Allow wins.
| URL path | Matching rule | Result |
|---|---|---|
| `/members/index.html` | `Disallow: /members/` | Blocked |
| `/members/public.html` | `Allow: /members/public.html` | Allowed |
| `/news/index.html` | No matching rule | Allowed |
This exception pattern is useful when blocking a directory but publishing one file from it.
User-agent: GPTBot
Disallow: /members/
Allow: /members/public-summary.htmlAn empty Disallow value means that nothing is disallowed:
User-agent: OAI-SearchBot
Disallow:By contrast, Disallow: / matches every path on that host.
The * character can match any sequence of characters in implementations that support the standard wildcard extension, and $ can mark the end of a path. Use these carefully because support and interpretation can vary between crawler products.
User-agent: *
Disallow: /*.pdf$This rule targets paths ending in .pdf. Test important rules against the documentation and parser used by your target crawlers.
Visualizing the decision
Common matching errors
- Putting a crawler's rules in a group that also names unrelated crawlers.
- Assuming the wildcard group adds restrictions to a more specific group.
- Using
Disallow: /privatewhen you mean only the/private/directory. The former can also match paths such as/privateer. - Forgetting that rules are advisory. A server must still protect confidential data with authentication and authorization.
Exercise
A file contains User-agent: GPTBot, Disallow: /, followed by User-agent: *, Allow: /. May GPTBot fetch /guide.html?
Show answer
No. GPTBot uses the specific group. Its Disallow: / rule matches the path, and the wildcard group's Allow rule does not override it.