Search Console reports "Blocked by robots.txt" for a page you want indexed. Or the opposite: you added a Disallow rule to keep crawlers out of your checkout, and they are still crawling it. Robots.txt looks simple, a few lines of plain text, but the way crawlers decide which rule applies is precise, and a single character can change the result.
This guide focuses on how rules are matched: which group of rules a crawler uses, how paths and wildcards are compared, and what happens when rules conflict. If you need to write a file from scratch, see how to write a robots.txt file; here the goal is to understand and test one.
The standard
Robots.txt was an informal convention for decades. In 2022 it was published as an internet standard, RFC 9309, largely based on how Google had described its own behaviour. Google, Bing and other major crawlers follow it closely, although some crawlers have their own extensions, and some ignore robots.txt entirely.
A file consists of groups. Each group starts with one or more User-agent lines followed by Allow and Disallow rules:
User-agent: *
Disallow: /cart/
Allow: /checkout/help
User-agent: Googlebot
User-agent: Bingbot
Disallow: /internal-search/
Sitemap: https://www.example.com/sitemap.xml
Step 1: which group applies?
A crawler looks for the group whose user-agent matches its own name most specifically, and only that group is used.
- Googlebot uses the
User-agent: Googlebotgroup above, not the*group. - A crawler with no group of its own falls back to
*. - Groups for the same user-agent that appear in different places are combined.
This is the most common source of surprises. In the example, /cart/ is disallowed for * but not in the Googlebot group, so Googlebot may crawl /cart/. Rules are not inherited from *. If you want Googlebot to follow the general rules as well, repeat them in its group.
Specific Google crawlers, such as Googlebot-Image, look for their own group first and fall back to the Googlebot group if there is none.
Step 2: which rules match the path?
Rules are compared with the URL path, including the query string, starting from the first character. Matching is case-sensitive for paths.
| Rule | Matches | Does not match |
|---|---|---|
Disallow: /cart |
/cart, /cart/, /cartoon |
/shop/cart |
Disallow: /cart/ |
/cart/, /cart/item |
/cart |
Disallow: /*?sort= |
/products?sort=price |
/products?page=2 |
Disallow: /*.pdf$ |
/brochures/menu.pdf |
/brochures/menu.pdf?v=2 |
Disallow: / |
everything | nothing |
Disallow: (empty) |
nothing | everything |
Two special characters are supported:
*matches any sequence of characters, including none.$anchors the rule to the end of the URL.
Note the /cart versus /cart/ difference: without the trailing slash, the rule also catches /cartoon.
Step 3: which matching rule wins?
When several rules match, the most specific rule wins, measured by the length of the rule's path. If an Allow and a Disallow rule are equally long, Google uses the less restrictive one, so Allow wins ties.
Example, in one group:
Disallow: /cart/
Allow: /cart/shared/
For /cart/shared/list-42, both rules match. /cart/shared/ is longer than /cart/, so the URL is allowed. For /cart/checkout, only the Disallow matches, so it is blocked.
The order of lines within a group does not matter for Google; length does.
Test rules with our tester
The Robots.txt Tester applies these rules and shows exactly which line decided the result.
- Open the Robots.txt Tester. Browsers cannot fetch another site's file, so open
yoursite.com/robots.txt, copy it and paste it into robots.txt content. - Read Parse results: the number of groups and rules, whether there is a
User-agent: *group, any Sitemap lines, and warnings for lines that could not be understood. - Pick a crawler under User-agent: Googlebot, Googlebot-Image, Googlebot-News, Bingbot, DuckDuckBot, Applebot, YandexBot, Baiduspider,
* (any other crawler), or Custom… for any other name. - Check the line Rules used, which shows which group the crawler follows and its line number.
- On Test a URL, enter a URL or path. The result shows Allowed or Blocked, the reason, and the deciding rule with its line number. If several rules match, All matching rules lists them with their lengths.
- On Test many, paste one URL or path per line to see a table with the result and rule for each.
Other ways to test
Search Console. The robots.txt report shows the version Google last fetched and any parsing problems. The URL Inspection tool tells you whether a specific URL is blocked for Google. These are authoritative for Google, but only for verified sites and only for the live file.
Google's open-source parser. Google has published its robots.txt parser as open-source code. Developers can run it locally for exact Google behaviour.
Manual reading. For a short file, following the three steps above by hand works. Once there are wildcards and several groups, a tester saves mistakes.
Pitfalls
Robots.txt does not remove pages from search
It controls crawling, not indexing. A blocked URL can still appear in results if other pages link to it, usually without a description. To keep a page out of results, allow crawling and use a noindex meta tag or header, which you can confirm with the Meta Tag Analyzer.
Blocking CSS and JavaScript
Search engines render pages. Blocking the files that build the layout can make pages look broken to them.
Staging rules going live
Disallow: / copied from a staging site blocks everything. Test after every deployment.
Unsupported lines
Google ignores Crawl-delay and noindex lines in robots.txt. Other crawlers may honour crawl-delay.
To create a clean file, use the Robots.txt Generator, and make sure the Sitemap line points to a valid file from the XML Sitemap Generator. For redirects rather than blocks, the .htaccess Redirect Generator is the right tool.
Frequently asked questions
Does Googlebot follow the User-agent: * rules?
Only if there is no group specifically for Googlebot. When a Googlebot group exists, Googlebot follows that group alone.
Does the order of Allow and Disallow lines matter?
Not for Google. The longest matching rule wins, and Allow wins if an Allow and a Disallow rule are the same length.
Is robots.txt case-sensitive?
Paths are case-sensitive, so /Cart/ and /cart/ are different. User-agent names and directive names are not case-sensitive.
Why is a blocked page still in Google?
Blocking crawling does not remove a URL from the index. Google can list a blocked URL it knows from links. Use noindex, with crawling allowed, to remove it.
What does $ mean in robots.txt?
It marks the end of the URL. /*.pdf$ matches URLs ending in .pdf, but not .pdf?v=2.