Robots.txt Wildcards & Pattern Matching (RFC 9309)
A deep-dive technical guide to pattern matching rules, wildcards (*), and end-of-string anchors ($) in RFC 9309 robots.txt files.
AI Summary: Under RFC 9309, robots.txt supports the wildcard (*) representing any character sequence and the anchor ($) denoting the exact end of a URL path. When overlapping Allow and Disallow rules match a URL, the rule with the longest path pattern takes precedence.
The Modern Rules of Robots Pattern Matching
Historically, robots.txt pattern matching varied significantly across search engines. In September 2022, the Internet Engineering Task Force (IETF) published RFC 9309 (Robots Exclusion Protocol), formalizing wildcard syntax and rule precedence for all compliant crawlers.
Understanding RFC 9309 syntax prevents accidental site-wide de-indexing caused by improperly formatted wildcards.
Wildcard Syntax Essentials
1. The * Wildcard (Any Sequence of Characters)
Matches zero or more valid URL path characters:
# Disallow any URL containing "/temp/" anywhere in the path
User-agent: *
Disallow: /*/temp/*
# Disallow URLs with tracking query parameters
User-agent: *
Disallow: /*?*utm_*
2. The $ Anchor (End of URL Path)
Matches the exact terminus of the URL string:
# Block PDF files strictly, while allowing /docs/file.pdf.html
User-agent: *
Disallow: /*.pdf$
# Block URLs ending with a trailing slash
User-agent: *
Disallow: /*/$
The Law of Rule Precedence: Longest Match Wins
A common misconception is that Disallow always overrides Allow, or that the order of rules in the file dictates priority. Under RFC 9309:
When both an
Allowand aDisallowrule match the same URL, the rule with the longest character pattern takes precedence.
Precedence Example
User-agent: Googlebot
Disallow: /catalog/
Allow: /catalog/public/
For the URL https://example.com/catalog/public/item-123:
- Pattern
/catalog/has length 9. - Pattern
/catalog/public/has length 16. - Result: The crawler is ALLOWED because 16 > 9.
If the pattern lengths are identical, the more permissive directive (Allow) takes precedence.
4 Costly Wildcard Mistakes to Avoid
Disallow: /*: Blocks the entire website completely.- Missing Leading Slash (
Disallow: private/): Matches nothing; paths must begin with a forward slash/. - Case Sensitivity: RFC 9309 states paths are strictly case-sensitive.
Disallow: /*.PDF$will not matchfile.pdf. - Relying on
noindexin robots.txt: Thenoindexdirective inrobots.txtis deprecated and ignored by Googlebot since 2019.
Verify that your robots.txt wildcards and path precedence work as intended without blocking valuable content. Audit with Geolify.ai.