robots.txt syntax: groups, rules and matching
Reference for the robots.txt file format as standardized in RFC 9309: groups and user-agent lines, allow and disallow rules, the * and $ characters, comments, and the longest-match rule that decides which line applies to a URL.
Type: ReferenceVersionRFC 9309On this page
| Specification | RFC 9309, Robots Exclusion Protocol, IETF Standards Track, September 2022 |
|---|---|
| Authors | M. Koster, G. Illyes, H. Zeller, L. Sassman |
| Origin | A Standard for Robot Exclusion, agreed on the robots mailing list on 30 June 1994 |
| Location | /robots.txt at the top of each scheme, host and port (where site files live: the root path and /.well-known/) |
| Media type and encoding | text/plain, UTF-8 |
| Records defined | user-agent, allow, disallow |
| Minimum parsing limit | 500 KiB; crawlers may ignore content beyond their limit |
A complete file
The file below has two groups and a Sitemap line. The sections that follow explain each part, and the tables near the end show which rule applies to a set of example URLs.
# robots.txt for www.example.com
# Group 1: two named crawlers share one set of rules
User-agent: ExampleBot
User-agent: OtherBot
Disallow: /drafts/
Allow: /drafts/published/
Disallow: /*.pdf$
# Group 2: every crawler without a group of its own
User-agent: *
Disallow: /search
Disallow: /account/
Allow: /account/help
Sitemap: https://www.example.com/sitemap.xmlLines, records and comments
Each line holds one record: a name, a colon, and a value, with optional spaces or tabs around the colon. Names are matched without regard to case, so User-agent, user-agent and USER-AGENT are the same record. Line endings may be CR, LF or CRLF. A # starts a comment that runs to the end of the line, on a line of its own or after a rule. Blank lines are allowed anywhere and carry no meaning.
That last point differs from the 1994 document, in which a blank line separated one record from the next. Under RFC 9309 a group ends when a user-agent line follows its rules, or at the end of the file. A blank line between two disallow lines does not split them into separate groups.
Groups and user-agent lines
A group is one or more user-agent lines followed by the rules that apply to the crawlers named in them. The value of a user-agent line is a product token: the short name a crawler uses for itself, made only of letters, underscores and hyphens, such as Googlebot or GPTBot. RFC 9309 says the token should appear as a substring of the User-Agent header the crawler sends, which is how a site can connect log lines to robots.txt groups. Current tokens for AI crawlers are listed in AI crawler tokens for robots.txt.
- Matching is case-insensitive. A crawler whose token is ExampleBot obeys a group for examplebot.
- If more than one group names the same crawler, the crawler combines their rules into one group.
- A crawler that finds a group naming it obeys that group only and ignores the * group entirely. Rules for everyone are not inherited by a crawler that has its own group.
- A crawler with no group of its own obeys the group whose user-agent value is *. If there is no such group, no rules apply to it.
- Allow and disallow lines that appear before the first user-agent line belong to no group and should be ignored.
Allow and disallow rules
A rule pairs allow or disallow with a path. The path is matched against the beginning of the URL's path and query, starting at the first character, so Disallow: /search covers /search, /search?q=x and /searching-tips alike. A trailing slash narrows a rule to a directory: Disallow: /account/ does not cover /account-settings. Matching should be case-sensitive, so /Drafts/ and /drafts/ are different paths.
A disallow line with an empty value disallows nothing, and a group with no rules at all allows everything. A URL that matches no rule in the crawler's group is allowed. The file itself, /robots.txt, is always allowed, whatever the rules say.
Characters outside ASCII, and reserved characters, are compared in percent-encoded form. A rule written as Disallow: /docs/안내 and a request for /docs/%EC%95%88%EB%82%B4 refer to the same path.
Special characters
| Character | Meaning | Example | Matches | Does not match |
|---|---|---|---|---|
| * | Zero or more of any character | Disallow: /*/print | /guide/print, /a/b/print/2 | |
| $ | End of the URL | Disallow: /*.pdf$ | /files/report.pdf | /files/report.pdf?v=2 |
| # | Start of a comment | Allow: / # open site | Not part of the rule |
To match a literal * or $ in a URL, percent-encode it in the rule as %2A or %24. Crawlers must support all three characters.
Which rule wins
When several rules in a group match a URL, the crawler uses the most specific one, which RFC 9309 defines as the match with the most octets. Order in the file does not matter. If an allow rule and a disallow rule are equally specific, the allow rule should be used. Google documents that it also resolves conflicts involving wildcards in favor of the least restrictive rule.
| URL path | Rules that match | Rule applied | Result |
|---|---|---|---|
| /drafts/notes.html | Disallow: /drafts/ | Disallow: /drafts/ | Disallowed |
| /drafts/published/intro.html | Disallow: /drafts/ (8 octets); Allow: /drafts/published/ (18 octets) | Allow: /drafts/published/ | Allowed |
| /Drafts/notes.html | None, because matching is case-sensitive | None | Allowed |
| /files/report.pdf | Disallow: /*.pdf$ | Disallow: /*.pdf$ | Disallowed |
| /files/report.pdf?download=1 | None, because $ requires the URL to end after .pdf | None | Allowed |
| /search?q=sitemaps | None; ExampleBot has its own group and ignores the * group | None | Allowed |
| /robots.txt | Always allowed | Allowed |
| URL path | Rules that match | Rule applied | Result |
|---|---|---|---|
| /search?q=sitemaps | Disallow: /search | Disallow: /search | Disallowed |
| /searching-tips | Disallow: /search | Disallow: /search | Disallowed |
| /account/orders | Disallow: /account/ | Disallow: /account/ | Disallowed |
| /account/help | Disallow: /account/ (9 octets); Allow: /account/help (13 octets) | Allow: /account/help | Allowed |
| /account/helpdesk | Disallow: /account/; Allow: /account/help | Allow: /account/help | Allowed |
| /drafts/notes.html | None in the * group | None | Allowed |
Two of these results are frequent sources of surprise. /searching-tips is blocked because rules match prefixes, and /account/helpdesk is allowed for the same reason. Adding $ to the allow rule, as in Allow: /account/help$, limits it to the single URL.
Lines outside groups
RFC 9309 defines only user-agent, allow and disallow. Section 2.2.4 lets crawlers interpret other records, and names Sitemaps as the example, provided that parsing them does not interfere with the defined ones. In particular, a Sitemap line must not end a group. Google, Bing and other search engines read Sitemap lines; each takes a full URL, a file may list several, and they apply to the whole file rather than to the group they happen to follow.
Other names that appear in real files, such as Crawl-delay or Host, are not part of the standard. Google's documentation says its parser ignores every field except user-agent, allow, disallow and sitemap. Content-Signal and Content-Usage lines, which express how content may be used rather than whether it may be fetched, are covered in usage preferences beyond allow and disallow.
Errors, caching and limits
- A crawler must use every rule it can parse, even if other lines in the file are malformed.
- If the file returns a 4xx status, the crawler may access everything. If it returns a 5xx status or cannot be reached, the crawler must assume everything is disallowed. After a long outage (the RFC gives 30 days as an example), it may treat the file as unavailable or keep using a cached copy.
- Crawlers should follow at least five consecutive redirects to reach the file.
- A cached copy should not be used for more than 24 hours unless the file cannot be fetched.
- Crawlers should set a parsing limit, and the limit must be at least 500 KiB. Google ignores content after the first 500 KiB.
From 1994 to RFC 9309
Martijn Koster wrote A Standard for Robot Exclusion in 1994, after crawlers had overloaded servers and wandered into parts of sites where they were not wanted. The text was agreed on the robots mailing list on 30 June 1994 and was also open for discussion on the www-talk list. It defined only User-agent and Disallow lines, recommended a substring match on the robot's name, and said plainly that it was not an official standard.
Over the next 28 years crawlers added Allow lines, the * and $ characters and their own precedence rules, and implementations drifted apart. Koster, together with Gary Illyes, Henner Zeller and Lizzi Sassman of Google, took the protocol to the IETF, and it was published as RFC 9309 in September 2022. The RFC also states what the 1994 text left implicit: these rules are not a form of access authorization. What that means in practice is the subject of what robots.txt does not do.
See also
- AI crawler tokens for robots.txtThe robots.txt product tokens that OpenAI, Anthropic, Google, Apple, Perplexity, Common Crawl and Meta document for their crawlers and fetchers, what each operator says the token is for, and what it says about obeying robots.txt.
- Page-level rules: the robots meta tag and X-Robots-Tagrobots.txt decides whether a URL is fetched; the robots meta tag and the X-Robots-Tag header decide what a search engine may do with a page or file once it has been fetched, such as leaving it out of the index or showing no snippet.
- What robots.txt does not dorobots.txt asks crawlers not to fetch URLs. It does not protect content, hide paths, keep URLs out of search results or, for Google, carry noindex and crawl-delay rules. What to use for each of those instead.
- Where site files live: the root path and /.well-known/Clients find machine-readable site files at fixed addresses: some at the root of each host, some under the /.well-known/ prefix of RFC 8615, and some inside every page. Where a file sits also decides which URLs it can speak for.
- How crawlers find a sitemapA sitemap only helps once a crawler knows where it is. The Sitemap line in robots.txt, submission in Google Search Console and Bing Webmaster Tools, the retired ping endpoint, and IndexNow for announcing changed URLs.
References
- Koster, M., Illyes, G., Zeller, H. and Sassman, L. RFC 9309: Robots Exclusion Protocol. IETF, September 2022. rfc-editor.org
- Koster, M. A Standard for Robot Exclusion (1994). The Web Robots Pages. robotstxt.org
- Google Search Central. How Google interprets the robots.txt specification. developers.google.com