Robots.txt (RFC 9309)
Technical guide to RFC 9309 (Robots Exclusion Protocol): how crawlers resolve user-agent groups, apply longest-match Allow/Disallow precedence, handle HTTP status codes, and avoid common indexing pitfalls.
Robots.txt & RFC 9309: The Robots Exclusion Protocol
A robots.txt file instructs web crawlers which URL paths on an origin they are allowed or disallowed from fetching. Published in September 2022, RFC 9309 standardized the core parsing and matching rules of the Robots Exclusion Protocol across major search engines.
This guide focuses on the specification details that most frequently trip up engineering teams in production:
- Section 2.1: How parsers group rules and match
User-agentproduct tokens. - Section 2.2.2: How
AllowandDisallowrules compete using longest-match (octet length) precedence—and whyAllowwins ties. - Section 2.3: How HTTP status codes (
2xx,3xx,4xx,5xx) on/robots.txtalter crawler behavior across an entire domain.
robots.txt Is Not an Access Control Mechanism]
robots.txt is a public advisory file—not authentication, authorization, or a firewall. Anyone can fetch /robots.txt directly, and non-compliant bots will ignore it altogether.
File Location and Origin Scope
The file must reside at the top-level root of the origin, be named /robots.txt (all lowercase), and be served as UTF-8 text/plain:
Because robots.txt is scoped strictly per authority (scheme + host + port), https://example.com/robots.txt, https://www.example.com/robots.txt, and https://api.example.com/robots.txt are completely separate files. Placing a file in a subdirectory such as /booking/robots.txt has zero effect.
A minimal file that explicitly allows all crawlers to fetch every path:
An empty Disallow: value declares that no paths are blocked, making your intent clearer than serving an empty zero-byte file.
How Crawlers Parse robots.txt
1. Grouping Rules
A group begins with one or more consecutive User-agent lines followed by Allow and Disallow rules. The group ends when the parser encounters the next User-agent line (after at least one rule) or reaches the end of the file:
Any Allow or Disallow rules appearing above the very first User-agent line do not belong to a valid group and are ignored. Comments start with # and can occupy an entire line or trail after a directive:
2. Matching the User-agent Group
Each User-agent line specifies a crawler product token (letters, hyphens, and underscores). Parsers match product tokens using case-insensitive substring matching.
For example, the following group matches HotelBot, hotelbot, or Mozilla/5.0 (compatible; HotelBot/1.0):
When a crawler evaluates robots.txt, it selects its active rule set using two precedence rules:
- Specific match overrides wildcard (
*): If one or more groups explicitly match the crawler's product token, the crawler merges only those matching groups and completely ignores theUser-agent: *fallback group. - Wildcard fallback: If no specific
User-agentgroup matches, the crawler falls back toUser-agent: *.
In the example above, Googlebot matches the specific Googlebot group and only obeys Disallow: /private/—it is not blocked from /tmp/ unless you repeat Disallow: /tmp/ inside the Googlebot group.
3. Resolving Allow vs. Disallow (Longest-Match Precedence)
Once the crawler selects its applicable group, it compares the target URL's path and query string against every rule in that group:
- A rule matches from the first octet of the path (
/…). - When multiple rules match a URL, the most specific rule—the pattern with the longest matching byte/octet length—wins.
- Tie-breaker: If a matching
Allowrule andDisallowrule have the exact same pattern length,Allowwins.
If an Allow and Disallow rule share the exact same length, RFC 9309 specifies that Allow takes precedence:
Here /public/ is allowed—though in practice you should avoid writing contradictory duplicate patterns.
Pattern Matching: Prefixes, *, and $
By default, every rule pattern is a prefix match: Disallow: /private/ matches /private/, /private/a, and /private/a/b.html.
RFC 9309 standardizes two special wildcard characters inside patterns:
*: Matches zero or more instances of any character.$: Anchors the match to the end of the URL path/query.
This configuration blocks any URL ending in .json except /api/public.json (which wins via longest match). Note that crawlers evaluate percent-encoded URI paths—keep non-ASCII or reserved characters properly percent-encoded when writing rules.
Note also that /robots.txt itself is always implicitly allowed; writing Disallow: / never prevents a crawler from fetching /robots.txt.
Production Example: Hospitality / E-Commerce Website
A hotel or e-commerce site typically has high-value landing pages that should be crawled alongside transactional, session-bound, or faceted filter URLs that waste crawl budget:
Avoiding Overly Broad Prefix Blocks
Suppose your site uses the following URL structure:
/rooms/deluxe— Public room detail page (must be indexed)/booking/packages— Public promotional packages page (must be indexed)/booking/search— Interactive date/guest picker form (no search value)/booking/confirmation— Post-checkout receipt page (must not be crawled)
Block the specific transactional paths rather than the entire /booking/ prefix:
Avoid writing Disallow: /booking/ if public landing pages like /booking/packages live under that prefix.
Similarly, be careful with the "deny-all, allow-selectively" pattern:
Because Disallow: / has length 1, it blocks the homepage (/) and every top-level asset (CSS, JS, images, and pages) that does not start with /rooms/. Unless you are intentionally locking down an entire subdomain except one subfolder, block specific paths instead.
How HTTP Status Codes on /robots.txt Affect Crawling
Crawlers react not only to the text inside /robots.txt, but also to the HTTP status code returned when fetching it (RFC 9309 Section 2.3):
/robots.txt Uptime Separately]
A transient 503 Service Unavailable or origin timeout on /robots.txt can halt Googlebot crawling across your entire domain, whereas accidentally returning 404 removes all crawl protections at once. Monitor /robots.txt status codes, Content-Type, and CDN caching in your production alerting.
Crawlers typically cache /robots.txt for up to 24 hours. Whenever you deploy a rule change, verify the live response through your CDN and reverse proxy (curl -i https://example.com/robots.txt) and purge edge caches if needed.
Security Reminder: robots.txt Does Not Protect Sensitive Routes
Never list secret URLs, private tokens, or unauthenticated admin endpoints in robots.txt assuming it will hide them. Because /robots.txt is world-readable, attackers and security scanners routinely scrape it first to discover sensitive paths.
To protect /admin/, /account/, or private APIs:
- Enforce authentication and authorization on the server.
- Use
<meta name="robots" content="noindex">orX-Robots-Tag: noindexwhen a public page must be excluded from search results (and keep it crawlable inrobots.txtso the crawler can read thenoindexdirective).
Pre-Deployment Checklist
- Fetch
https://your-domain.example/robots.txton the production hostname and confirm it returnsHTTP 200, UTF-8 encoding, andContent-Type: text/plain. - Audit specific
User-agentblocks alongsideUser-agent: *—remembering that a specific match replaces the*block rather than inheriting from it. - Test critical landing pages, assets (JS/CSS/images), and transactional routes against the longest-match rule.
- Check equal-length rule ties (
Allowwins overDisallow). - Verify query parameters, percent-encoding, trailing slashes, and CDN redirect rules.
- Declare your Sitemap.xml using an absolute URL and confirm the sitemap path itself is not blocked by
Disallow. - Use the interactive Robots + Sitemap Inspector to test path rules against search and AI crawlers (
Googlebot,GPTBot,ClaudeBot).