Which wins in robots.txt, Allow or Disallow?

By TechCompare · Updated · How we check

The most specific rule wins, which means the one with the most characters in its pattern. On a tie, Allow wins.

When both an Allow and a Disallow rule match a path, the longer pattern wins. If they're the same length, Allow wins. The order of the lines inside a group doesn't change that. RFC 9309 and Google's documentation agree, and the tester shows the rule it used for every verdict.

Topic
Allow vs Disallow
Rule precedence
Category
Reading the rules
Precedence, wildcards and size

How it works

Take a group with Disallow: /shop/ and Allow: /shop/sale/. A page at /shop/sale/shoes matches both. The Allow pattern is 11 characters and the Disallow is 6, so the page is allowed. A page at /shop/new matches only the Disallow, so it's blocked. Swap the two lines and nothing changes. RFC 9309 says the most specific match must be used, measured by the most octets, and that on a tie between equivalent rules the allow rule should be used. Google says it uses the longest matching path, and the least restrictive rule if conflicts remain. A broad block with a narrow exception works the same way: Disallow: / with Allow: /public/ blocks the site and lets /public/ pages through. Rules only compete inside one group. If a group is made for the crawler, the * group is ignored for it, and the two are never combined. Rules in other groups can't beat the ones it reads. One path is always allowed: /robots.txt itself.

Verdict

Make the rule you want to win the longer one, then test two paths, one that should be allowed and one that shouldn't, with the crawler you care about. The tester names the line that decided each verdict, so a wrong guess shows up at once.

More Robots.txt scenarios

Block GPTBot
Two lines tell OpenAI's training crawler to stay out. Its search crawler and its page visits use other names.
View details
Google-Extended
A token for Gemini training, not a crawler. A rule for it never reaches Googlebot or Google Search.
View details
Block AI, keep search
Name each training crawler, leave Googlebot and Bingbot alone, and choose on purpose about the AI search bots.
View details

Frequently asked questions

Does the order of lines matter?
Not for crawlers that follow RFC 9309, like Googlebot. The longest matching pattern wins wherever it sits in the group. Google says the order of groups doesn't matter either.
Do rules in different groups compete?
No. A crawler follows one group: the one that names it, or the * group if none does. Google says groups for a specific agent and the * group aren't combined, so a Disallow under * can't beat an Allow in a group made for Googlebot.
What happens when two rules have the same length?
Allow wins. RFC 9309 says the allow rule should be used, and Google says it uses the least restrictive rule when conflicts remain.