Robots.txt wildcards

robots.txt supports just two special characters: * matches any run of characters and $ marks the end of the URL. There’s no regex, no ? wildcard, and matching is case-sensitive.

Try a pattern

The paths below come from Google’s own wildcard table. Change the rule and watch which ones it catches.

Disallow:

2 of 15 paths match (and would be blocked).

  • /allowed
  • /fishallowed
  • /fish.htmlallowed
  • /fish/salmon.htmlallowed
  • /fishheadsallowed
  • /fish.php?id=anythingallowed
  • /Fish.aspallowed
  • /catfishallowed
  • /?id=fishallowed
  • /index.phpblocked
  • /folder/filename.phpblocked
  • /filename.php?parametersallowed
  • /filename.php/allowed
  • /windows.PHPallowed
  • /fishheads/catfish.php?parametersallowed

How matching works

  • Rules are compared from the start of the path, including the query string. /fish matches /fish.php?id=1 but not /catfish.
  • * matches zero or more of any character, including / and ?. A trailing * changes nothing: /fish* equals /fish.
  • $ is only special at the very end. /*.php$ matches /a.php but not /a.php?x=1.
  • Paths are case-sensitive: /*.php does not match /windows.PHP.
  • Non-ASCII characters are compared in percent-encoded form, so /café and /caf%C3%A9 are the same rule (RFC 9309 §2.2.2).

Wildcards and precedence

When Allow and Disallow both match, the longer rule path wins, and * counts as a character. That’s why Disallow: /*.htm (6 characters) beats Allow: /page (5) for /page.htm. Step through all six of Google’s cases in the tester.

Common mistakes

  • Disallow: *.pdf: no leading slash. Write /*.pdf.
  • Disallow: /*? blocks every URL with a query string, including paginated and tracked links you may want crawled.
  • Disallow: /private*/ works, but /private alone already covers /private-files/ and /privately. Be sure that’s what you want.
  • Expecting $ to work mid-path, as in /a$b. It’s taken literally there.

Questions

Does robots.txt support regular expressions?

No. Only * (any characters) and $ (end of URL). Characters like ?, + and . have no special meaning.

Do all crawlers support wildcards?

RFC 9309 requires * and $, and Google, Bing and other major search engines support them. Very old or simple crawlers may treat them literally.

Sources: Google: URL matching based on path values; RFC 9309 §2.2.3 Special characters.