Path matching — *, $, longest rule, Allow first
Path rules in robots.txt are not regular expressions; they follow the small matching algorithm defined by RFC 9309. Three pattern forms and two precedence rules are enough to work out almost any verdict by hand. This page implements the same rules in JavaScript and checks its results against an independent Python implementation.
Three pattern forms
- Prefix match —
/adminmatches/admin,/admin/usersand even/administrator. A path matches when it starts with the pattern. - Wildcard
*— any run of characters./*.pdf$matches any path ending in.pdf, wherever it sits. - End anchor
$— special only as the last character./list$matches/listbut not/list?page=2or/listing.
User-agent: * Disallow: /private/ Allow: /private/public/ Disallow: /*.pdf$ Allow: /docs/*.pdf$
| Path | Rule that matched | Verdict |
|---|---|---|
/private/note | Disallow: /private/ | Blocked |
/private/public/note | Allow: /private/public/ (longer) | Allowed |
/docs/guide.pdf | Allow: /docs/*.pdf$ (longer) | Allowed |
/files/report.pdf | Disallow: /*.pdf$ | Blocked |
/list | Disallow: /list$ | Blocked |
/list?page=2 | Disallow: /list$ does not match, and without Disallow: /list | Allowed |
The longest rule wins
When several rules match, the one with the longest pattern is chosen. Length is measured on the pattern string, not on the path that matched, which is why /private/public/ beats /private/. Each verdict card in this page shows the pattern length and the line of the rule that decided.
For that reason, an exception must be longer than the block it escapes. Allow: /private is shorter than Disallow: /private/ and therefore has no effect at all.
On equal length, Allow wins
When two patterns are exactly the same length, Allow takes precedence. With both Allow: /page and Disallow: /page present, /page is allowed. In practice, do not leave contradictory rules of equal length in a file; settle on one.
With no matching rule, the path is allowed. A path you simply never mention is not blocked. To make blocking the default, use Disallow: / and reopen only the paths that must stay available with Allow.
Percent encoding and the query string
Crawlers compare the percent-encoded form of the URL path: a space becomes %20 and a non-ASCII character becomes the %XX bytes of its UTF-8 encoding. A rule written with non-ASCII characters is encoded the same way here, so the verdict matches a real crawler.
Disallow: /검색is compared as/%EA%B2%80%EC%83%89.Disallow: /a%20b/blocks/a b/; both the rule and the URL are normalised to the encoded form.- The query string is part of the comparison.
Disallow: /*?sort=blocks URLs carrying a sort parameter while leaving/listalone. - Blocking query strings can remove pages from the index, so if the goal is to tidy filter URLs, use canonical tags as well.
Common misunderstandings
- Believing regular expressions work. RFC 9309 defines only
*and a trailing$; a?or+is compared as a normal character. - Believing paths are case-insensitive. Directive names are, paths are not.
- Believing
Disallow: /file.htmlleaves/file.html?x=1alone. Prefix matching still blocks it. - Believing rule order sets priority. Order does not matter; only pattern length does.
Questions
How is pattern length counted?
As the length of the percent-encoded pattern, with a trailing <code>$</code> excluded. This page and the Python implementation used for verification share that definition.
What does a pattern of a single * do?
<code>Disallow: *</code> is the shortest pattern that matches every path. It behaves like <code>Disallow: /</code> but loses to any longer rule.
Is comparing the query string standard?
RFC 9309 works on the URL path, and the major crawlers include the query string when matching. This page follows that practice.
Enter a pattern and a path to see which rule won and why.
Open the toolThis 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.