Skip to content
Koit Academy

Websites & SEO

·

8 min read

Robots.txt Wildcards: How * and $ Match, With Examples

How the * and $ wildcards work in robots.txt, how Google chooses between rules that both match, and the patterns that block more than you meant.

By Koit Academy

Robots.txt has only two special characters, and between them they cause most of the accidents in the file. An asterisk in the wrong place blocks a whole section; a missing dollar sign blocks every address that merely starts with the one you meant. Neither mistake produces an error. The file looks fine, the site keeps working, and crawlers quietly stop visiting pages you wanted found.

This post works through how the two wildcards match, how Google decides between two rules that both match an address, and the patterns worth testing before they go live.

The two wildcards

Google’s description of how it interprets robots.txt supports two special characters in paths:

  • * matches any sequence of characters, including none.
  • $ marks the end of the address. Without it, a rule matches any address that begins with the path.

Everything else in a path is literal, and paths are case sensitive: a rule for /Fish does not block /fish. Field names and user-agent names, on the other hand, are not case sensitive.

Matching from the start

Every rule is matched against the address from its beginning: the path, and the query string if there is one. That has two consequences that surprise people.

First, a rule without a wildcard is already a prefix match. Disallow: /search blocks /search, /search?q=roof, /search/help and also /searching-for-staff/, because all of them begin with /search. If you meant only the search page and its results, Disallow: /search? or a $ anchor says so more precisely.

Second, a leading asterisk is needed to match something in the middle of an address. Disallow: /*?sort= blocks any address containing ?sort= after any path; Disallow: ?sort= would match nothing, because no address begins with a question mark.

Seven rules and what they catch

RuleBlocksDoes not block
Disallow: /admin//admin/, /admin/users/administrator, /Admin/
Disallow: /*.pdf$/files/report.pdf/files/report.pdf?v=2, /pdf-guide/
Disallow: /*?sort=/shoes?sort=price, /a/b?sort=new/shoes?color=red&sort=price
Disallow: /*sort=/shoes?color=red&sort=priceaddresses without sort=
Disallow: /search$/search/search?q=roof, /search/help
Disallow: /p/p, /pricing, /products/, /privacy//about/

The third and fourth rows show a pattern that is easy to get wrong. A parameter that can appear anywhere in the query string is only reliably caught by a pattern without the question mark in front of it. The last row is the classic accident: a short prefix that was meant for one folder and blocks every page that starts with the same letter.

When two rules match: the longest wins

Most files have rules that overlap: a folder blocked, one page inside it allowed. Google resolves that with two rules of its own:

  1. The most specific rule wins, which Google defines as the rule with the longest path.
  2. If an allow and a disallow are equally long, Google uses the less restrictive one, the allow.
AddressMatching rulesLengthResult
/tmp/publicDisallow: /tmp/ and Allow: /tmp/public$5 and 12Allowed
/tmp/public/fileDisallow: /tmp/ only (the $ stops the allow)5Blocked
/pageDisallow: /page and Allow: /page5 and 5Allowed (tie)

Length is counted on the rule as written, wildcards included. It is a simple rule, and it means the order of lines in the file does not matter to Google: an allow written above a disallow and the same allow written below it behave the same.

The robots.txt tester applies exactly these rules to a file you paste, and shows every rule that matched an address along with the one that decided it.

Groups: which rules apply to which crawler

Wildcards only matter within the group of rules a crawler actually follows. Google’s crawlers follow one group: the one whose user-agent line names them most specifically. Groups naming the same crawler are merged, and the * group applies only when no group names the crawler.

The consequence is easy to miss. If a file has a group for Googlebot with one rule in it, Googlebot ignores every rule in the * group. A site that adds User-agent: Googlebot with a single line to allow one folder can accidentally unblock everything the * group was blocking for Google.

Lines that look like rules and are not

Google reads only user-agent, allow, disallow and sitemap lines. Crawl-delay, noindex and the various invented directives seen in old files are ignored. Google also reads only the first 500 KiB of the file; anything after that is not seen. Neither of these produces an error anywhere, which is why it is worth testing a file rather than reading it.

Patterns worth knowing

  • All files of a type: Disallow: /*.pdf$. The $ stops it matching /pdf-guide/.
  • A parameter anywhere in the query: Disallow: /*sessionid=.
  • One folder, one exception: Disallow: /private/ with Allow: /private/press-kit/. The allow is longer, so it wins for that folder.
  • Everything except one folder: Disallow: / with Allow: /public/. Rarely what anyone wants on a live site.

Rules for the usual problem areas

Most sites need wildcard rules for the same handful of areas, all of which can generate far more addresses than the site has pages:

  • Internal search results. Every search creates a new address. Block the results path or the search parameter, such as /search or /*?s=.
  • Sorting and filtering. A shop that adds ?sort= and ?color= to category pages can produce thousands of variations of the same list. Block the parameters that only reorder or narrow a list, and keep the category pages themselves crawlable.
  • Session and tracking parameters. Parameters that differ for every visitor add nothing for a crawler; a pattern such as /*sessionid= catches them anywhere in the query.
  • Printer-friendly and other duplicate views reached through a parameter such as ?print=1.

Each of these should be tested against a real address from the site before going live, because the exact parameter names and positions differ from one platform to another.

When a pattern is too broad

The quickest way to find an over-broad rule is to search the site for addresses it would match that you did not intend. Take each wildcard rule, think of the shortest real address on the site it could match, and test that address. A rule written for a parameter can match a page whose path happens to contain the same letters; a rule ending in a folder name without a trailing slash can match a page whose name starts the same way. If a test surprises you, make the rule longer and more specific rather than adding an allow rule to patch it, because every patch is another line to understand next year.

Other crawlers and the standard

The * and $ characters are part of the Robots Exclusion Protocol as standardized in 2022 as RFC 9309, which the major search engines follow. Smaller and older crawlers may not support them, and some ignore robots.txt altogether. Write rules so that a crawler that ignores the wildcards does nothing harmful, and do not rely on robots.txt to keep anything private.

Reading a robots.txt you inherited

Many sites carry a file written years ago by someone no longer around. Read it one group at a time. For each Disallow line, write down what it was probably meant to block, then test one address that should be blocked and one that should not. Lines that block nothing that exists any more can go; lines whose purpose nobody can explain should be tested before they are removed, not after.

A worked file for a small shop

Here is how the patterns combine in one file for a typical small online shop, with the reason for each line:

User-agent: *
Disallow: /cart/
Disallow: /checkout/
Disallow: /account/
Disallow: /*?sort=
Disallow: /*&sort=
Disallow: /search
Allow: /search/help/

Sitemap: https://www.example.com/sitemap.xml

The cart, checkout and account areas have nothing to offer a searcher. The two sort patterns catch the parameter whether it comes first in the query or later. The search results are blocked, with one help page inside the same path allowed, which works because the allow rule is longer. Category and product pages are untouched, because nothing in the file matches them. Before publishing a file like this, test a product page, a category page with a filter and a search result, and confirm each gets the answer you expect.

Test before you publish

Write the file, then test it against a list of addresses: the important pages that must stay crawlable, and the private or wasteful ones that should be blocked. Every surprising result is a pattern to fix before crawlers find it. The robots.txt generator writes a clean starting file using only the fields Google reads, and adds the Sitemap line; the XML sitemap generator builds the sitemap it points to.

Remember, finally, what robots.txt cannot do. A blocked address can still be listed in results; keeping a page out of the index is a job for noindex, explained in robots.txt vs noindex.

Sources, read November 14, 2026:

  • Google Search Central, How Google interprets the robots.txt specification: the * and $ wildcards, case-sensitive paths, the most specific group per crawler, the longest-rule and least-restrictive precedence, the supported fields and the 500 KiB limit.