Robots.txt looks like a simple file, but two characters make it far more powerful, and far more dangerous, than it first appears: the asterisk * and the dollar sign $. With them, a single line can block every URL with a query string, every PDF, or every page in any folder named "print". Without understanding exactly how they match, it is easy to block far more than intended, or far less.
This guide explains how robots.txt matching works, what each wildcard does, how rule precedence decides between competing rules, and how to write and test patterns safely.
How Robots.txt Rules Match URLs
Each Allow or Disallow rule contains a path pattern. A crawler compares the pattern with the path and query string of a URL, starting from the first character after the domain.
For the URL https://example.com/shoes/aero-glide/?colour=navy, the part being matched is:
/shoes/aero-glide/?colour=navy
Three key principles:
- Rules match from the start of the path. A rule beginning with
/shoesonly matches paths that begin with/shoes. - Rules are prefix matches by default.
Disallow: /shoesmatches/shoes,/shoes/,/shoes/aero-glide/and also/shoes-guide/. - Paths are case-sensitive.
Disallow: /Shoes/does not match/shoes/.
Google's robots.txt specification defines these rules, and most major crawlers follow the same approach.
The Asterisk: Match Any Characters
* matches any sequence of characters, including none.
| Rule | Matches | Does not match |
|---|---|---|
Disallow: /*? | /shoes/?colour=navy, /search?q=boots | /shoes/ |
Disallow: /*sort= | /shoes/?sort=price, /boots?page=2&sort=name | /shoes/sorted-guide/ (no sort=) |
Disallow: /*/print/ | /guides/print/, /blog/post/print/ | /print/ at the root (needs a folder before it) |
Disallow: /*.pdf | /files/guide.pdf, /guide.pdf?download=1 | /guides/pdf-tips/ |
Note that a trailing * is redundant, because rules are already prefix matches. Disallow: /shoes* behaves the same as Disallow: /shoes.
The Dollar Sign: Match the End
$ anchors a pattern to the end of the URL. Nothing may follow it.
| Rule | Matches | Does not match |
|---|---|---|
Disallow: /*.pdf$ | /files/guide.pdf | /files/guide.pdf?download=1 |
Disallow: /shoes/$ | /shoes/ exactly | /shoes/aero-glide/ |
Allow: /$ | The home page only | Any other page |
$ is useful when you want to target a file type or an exact URL without catching variations.
Tip: When you block a file type, decide whether URLs with parameters, such as
guide.pdf?download=1, should also be blocked. With$, they will not be.
How Rule Precedence Works
When several rules in the same group match a URL, the crawler must choose one.
The longest matching rule wins
The rule with the longest path pattern that matches the URL takes precedence, regardless of the order in the file.
User-agent: *
Disallow: /shop/
Allow: /shop/guides/
For /shop/guides/boots/, both rules match. /shop/guides/ (13 characters) is longer than /shop/ (6 characters), so Allow wins and the URL is crawlable.
Ties go to Allow
If an Allow and a Disallow rule are the same length and both match, Google uses the less restrictive rule, Allow.
Wildcards count towards length
Pattern length is measured by the characters in the rule, including wildcards. This can produce surprising results when wildcard rules compete with plain ones, so test rather than assume.
How Crawlers Choose a Group
Before matching rules, a crawler chooses which group applies to it:
- It looks for the group whose
User-agentline most specifically matches its name - If it finds one, it follows only that group
- If none match, it follows the
User-agent: *group
User-agent: *
Disallow: /search/
Disallow: /cart/
User-agent: Googlebot
Disallow: /beta/
Here Googlebot follows only its own group. It may crawl /search/ and /cart/, because the * rules do not apply to it. If you want Googlebot to follow them too, repeat them in the Googlebot group.
Common Wildcard Patterns
Block all URLs with query strings
Disallow: /*?
Powerful and risky. It blocks every parameter URL, including pagination, product variants and campaign landing pages. Use only if you are certain no parameter URLs should be crawled.
Block a specific parameter wherever it appears
Disallow: /*?sort=
Disallow: /*&sort=
Two rules are needed: one for when the parameter comes first, one for when it follows another parameter.
Block a file type
Disallow: /*.pdf$
Block a folder name at any depth
Disallow: /*/print/
Block internal search
Disallow: /search
Disallow: /*?q=
Allow one subfolder inside a blocked folder
Disallow: /resources/
Allow: /resources/guides/
Mistakes Wildcards Make Easy
Blocking more than intended
Disallow: /*? blocks product variant URLs such as /product/?variant=123, which may be the main way products are linked.
Prefix collisions
Disallow: /shop also blocks /shop-guide/ and /shopping-list/. Use Disallow: /shop/ to target only the folder.
Forgetting parameter order
Disallow: /*?sort= misses /shoes/?colour=navy&sort=price, where sort is not the first parameter.
Case mismatches
Disallow: /*.PDF$ does not block /guide.pdf.
Using regex syntax
Robots.txt does not support regular expressions. Characters like ., +, [ ] and ( ) are treated literally, except * and $.
Assuming order matters
Within a group, rule order does not decide precedence; length does.
Worked Matching Examples
Consider this file:
User-agent: *
Disallow: /shop
Allow: /shop/guides/
Disallow: /*?sort=
Disallow: /*.pdf$
How do these URLs fare?
| URL path | Matching rules | Winner | Result |
|---|---|---|---|
/shop/boots/ | Disallow: /shop | Disallow | Blocked |
/shop-guide/ | Disallow: /shop | Disallow | Blocked (prefix collision) |
/shop/guides/sizing/ | Disallow: /shop, Allow: /shop/guides/ | Allow (longer) | Allowed |
/boots/?sort=price | Disallow: /*?sort= | Disallow | Blocked |
/boots/?colour=navy&sort=price | None (?sort= not present) | — | Allowed |
/files/price-list.pdf | Disallow: /*.pdf$ | Disallow | Blocked |
/files/price-list.pdf?v=2 | None ($ requires the end) | — | Allowed |
/SHOP/boots/ | None (case-sensitive) | — | Allowed |
Several of these results are probably not what the file's author intended: /shop-guide/ is blocked by accident, the second sort URL slips through, and the PDF with a version parameter is crawlable. Each is easy to fix once you can see it:
- Change
Disallow: /shoptoDisallow: /shop/ - Add
Disallow: /*&sort= - Change
Disallow: /*.pdf$toDisallow: /*.pdfif parameter versions should also be blocked
Wildcards and Crawl Budget
Wildcards are most often used to stop crawlers wasting time on low-value URL variations. Before reaching for them, consider whether other fixes would work better:
- Stop generating the URLs in internal links, such as using buttons instead of links for sorting
- Canonicalise variations that should consolidate to a main URL
- Noindex variations that are already indexed and need removing
Robots.txt is the right tool when variations are numerous, already out of the index, and clearly worthless to crawl.
How to Test Wildcard Rules Safely
Because wildcard rules can match thousands of URLs, never deploy one without testing it against real URLs from your site.
- Collect real URLs from a crawl, sitemaps and server logs, including parameter variations
- Test the current file to see what is allowed and blocked today
- Test the proposed file with the new rule
- Compare the two and review every URL whose status changes
A robots.txt change checker does steps 2 to 4 in one go: paste the current and proposed files with your URL list, and it lists every URL whose access changes for each crawler, with the rule responsible.
Example: Fixing an Overbroad Rule
Imagine a shop whose crawl budget is being wasted on sort and filter URLs. A developer proposes:
Disallow: /*?
A change check shows that 1,800 product variant URLs, used throughout the site's internal links, would become blocked for Googlebot, along with paginated category pages.
The team replaces it with targeted rules:
Disallow: /*?sort=
Disallow: /*&sort=
Disallow: /*?view=
Disallow: /*&view=
A second check shows only sort and view URLs changing. The rules are deployed, and crawl activity shifts from duplicate URLs to products.
Wildcard Cheat Sheet
| Goal | Rule |
|---|---|
| Block a folder only | Disallow: /folder/ |
| Block anything starting with a prefix | Disallow: /prefix |
| Block one exact URL | Disallow: /exact-page/$ |
| Block all query strings | Disallow: /*? |
| Block one parameter anywhere | Disallow: /*?param= and Disallow: /*¶m= |
| Block a file type exactly | Disallow: /*.pdf$ |
| Block a file type with or without parameters | Disallow: /*.pdf |
| Block a folder name at any depth | Disallow: /*/folder/ |
| Allow a subfolder inside a blocked folder | Disallow: /a/ plus Allow: /a/b/ |
| Allow only the home page | Disallow: / plus Allow: /$ |
Keep this alongside a tester, and check every pattern against real URLs before it goes live.
Wildcards and Case Sensitivity
Robots.txt path matching is case-sensitive. Disallow: /Private/ blocks /Private/report.pdf but not /private/report.pdf. Wildcards do not change this: Disallow: /*.PDF$ does not block files ending in .pdf. If your site serves the same content at different cases, either normalise URLs with redirects or include rules for each version.
Wildcards Do Not Remove Pages From Search
Blocking a URL pattern stops crawling, not indexing. A blocked URL can still appear in search results, usually without a description, if other pages link to it. To keep pages out of the index, allow crawling and use a noindex directive instead, or remove the pages. Google's robots.txt introduction explains this distinction.
Common Mistakes
- Testing with invented URLs
- Using
/*?without checking what it blocks - Forgetting the
&variant of parameter rules - Ignoring case sensitivity
- Assuming regex works
- Forgetting that crawler-specific groups replace the
*group
Frequently Asked Questions
Does robots.txt support regular expressions?
No. Only * (any characters) and $ (end of URL) have special meaning.
Is a trailing asterisk needed?
No. Rules are prefix matches, so a trailing * changes nothing.
Do all crawlers support wildcards?
Google, Bing and most major crawlers do. Some older or simpler bots may not.
Does rule order matter?
Not within a group for Google. The longest matching rule wins, and ties go to Allow.
Can I block a parameter without blocking the page?
Yes, with rules like Disallow: /*?sort= and Disallow: /*&sort=, which block only URLs containing that parameter.
Two characters give robots.txt its power, and its risk. Before deploying any wildcard rule, compare it with your current file against real URLs using the free Robots.txt Change Checker, and make sure it blocks exactly what you intend and nothing more.
Printed from seo-serps.com — https://seo-serps.com/seo-search-marketing/robots-txt-wildcards-explained-how-and-really-match-urls/ — updated November 23, 2026.