robots.txt Wildcards: How * and $ Patterns Work

In robots.txt, * matches zero or more characters and $ anchors the match to the end of the URL pattern. These are limited pattern operators, not full regular expressions. Crawlers compare applicable Allow and Disallow paths and use the most specific match; if equally specific rules conflict, Allow should win.

URL paths passing through wildcard, exact-ending, and longest-match robots.txt rule selection

Copy-paste robots.txt example

User-agent: *
Disallow: /*.pdf$
Disallow: /search?*sort=
Disallow: /private/*/draft/
Allow: /private/*/draft/public-summary.html$

Robots.txt uses limited pattern matching

The Robots Exclusion Protocol defines two special pattern characters for Allow and Disallow paths. The asterisk * represents zero or more characters, and the dollar sign $ marks the end of the match. They are useful, but they do not turn robots.txt into a complete regular-expression language.

Do not confuse the path wildcard with User-agent: *. In the User-agent field, the asterisk selects crawlers that do not have a more specific matching group. In a path rule, it matches characters inside a URL pattern.

Use $ for exact endings

To block URLs that end in .pdf, anchor the suffix:

User-agent: *
Disallow: /*.pdf$

The ending anchor prevents the rule from also matching a URL such as /file.pdf?download=1. Whether that query variant should also be blocked depends on your goal; test the real URL forms your site generates.

Use * for variable segments

An asterisk can cover changing folders, filenames, or parameters:

User-agent: *
Disallow: /search?*sort=
Disallow: /private/*/draft/
Allow: /private/*/draft/public-summary.html$

The first rule targets search URLs containing a sort parameter after the shown prefix. The second targets draft folders at varying path levels. The longer Allow rule reopens one exact public summary.

The longest matching rule wins

Crawlers compare all applicable Allow and Disallow paths and select the most specific match, measured by the length of the matched pattern. If two equivalent rules conflict, the protocol says Allow should be used.

User-agent: ExampleBot
Disallow: /media/
Allow: /media/public/
Disallow: /media/public/raw/

Here, /media/public/logo.svg is allowed, while /media/public/raw/source.svg is disallowed by the longer rule. Rule order is not a reliable substitute for specificity.

Matching is case-sensitive for paths

Path comparison should be case-sensitive. A rule for /Private/ may not match /private/. Percent-encoded characters also require care, because the protocol defines how URI characters are encoded and compared. Test the final URLs rather than reasoning only from a CMS route name.

Common wildcard mistakes

  • Treating * as one character instead of zero or more.
  • Forgetting $ when only an exact suffix should match.
  • Using regular-expression syntax that robots.txt does not define.
  • Assuming the last rule in the file automatically wins.
  • Testing only a folder and not its query-string or case variants.
  • Publishing a broad wildcard rule that affects search crawlers unintentionally.

Test representative URLs

Before publishing, prepare a small matrix of URLs that should be allowed and disallowed. Run each one through the robots.txt checker with the exact crawler token. Include boundary cases: the folder itself, nested pages, similar filenames, uppercase variants, parameters, and the exact suffix.

For the underlying fields, review Disallow, Allow, and User-Agent matching.

FAQ

What does * mean in robots.txt?

In an Allow or Disallow path, * represents zero or more characters. It is a wildcard, not a full regular-expression operator.

What does $ mean in robots.txt?

The dollar sign anchors the pattern to the end of the URL match. It is useful for exact filenames or suffixes such as /*.pdf$.

Does the last matching robots.txt rule win?

No. The most specific matching path is used. If equally specific Allow and Disallow rules conflict, Allow should win.

Are robots.txt paths case-sensitive?

They should be compared case-sensitively. Test uppercase, lowercase, encoded characters, and query variants that your site actually serves.

Are robots.txt wildcards the same as regular expressions?

No. The standard defines * and $ for path matching, but common regex constructs such as character classes, alternation, and lookarounds are not part of robots.txt syntax.

Related tools

Related pages