How do * and $ work in robots.txt?
By TechCompare · Updated · How we check
Use * for any text and $ to anchor the end. A pattern without them is a prefix, and matching is case sensitive.
Only two characters are special in a robots.txt path. The * matches any run of characters, including none, and $ means the URL ends here. Everything else matches itself. Every pattern is also a prefix match from the start of the path, which is why Disallow: /private blocks more than people expect.
How it works
Google's examples show where patterns land. Disallow: /*.pdf$ blocks /files/a.pdf but not /files/a.pdf?dl=1, because the query string is part of what's matched and the URL no longer ends in .pdf. Drop the $ and both are blocked. Disallow: /*?sort= blocks /list?sort=price. Disallow: /private blocks /private-notes and /private/x alike, while Disallow: /private/ only blocks the folder. Google says a trailing wildcard is ignored, so /fish* is the same as /fish. Matching is case sensitive, so Disallow: /Photos/ doesn't block /photos/a. RFC 9309 defines only * and $, so regular expression syntax like (jpg|png) isn't part of the language. The tester shows the pattern that matched, so you can see whether the rule you meant is the one that fired. When a pattern matches nothing, check the case and the slash first.
Verdict
Start from the URLs you want blocked and write the shortest pattern that catches them, with $ when the end matters. Then test one URL that should match and two near misses, like the same path in another case and with a query string. The near misses are where patterns go wrong.
More Robots.txt scenarios
Frequently asked questions
Does Disallow: /*.pdf$ block links with a query string?
Is robots.txt case sensitive?
Can I use a regular expression?
Related tools
Open Graph Visualizer
Preview how your website links will look when shared on Google, Twitter, Facebook, and Discord.
Use toolSSL Checker
Check a site's certificate, TLS versions, HTTP/2 and HTTP/3 support, post-quantum key exchange, HSTS and redirects, or compare two sites.
Use toolDNS Lookup
Look up a domain's DNS records on Cloudflare or compare several resolvers at once, and read its SPF, DMARC and DKIM records in plain words.
Use tool