How Robots.txt Rule Matching Actually Works

Understand crawler-group selection, longest-path matching, Allow and Disallow precedence, and what a robots.txt test can—and cannot—prove.

SharePost on XShare on LinkedIn
Watercolor illustration of a small crawler following branching cobalt paths through blue and coral access gates

The short answer

Select the most specific user-agent group for the crawler, collect its Allow and Disallow rules, and apply the rule with the longest matching path. When equally specific Allow and Disallow rules conflict, Allow wins under the standard matching model used by Google.

A robots.txt file can look like a top-to-bottom list of instructions. Crawlers do not simply stop at the first line that resembles the URL.

They first select the applicable crawler group, then compare matching path rules by specificity.

Select the crawler group first

A group begins with one or more User-agent lines followed by its rules. A crawler looks for the most specific user-agent token that matches its name. The wildcard group applies when no more specific group matches.

For example:

User-agent: ExampleBot
Disallow: /private/

User-agent: *
Allow: /

ExampleBot uses its named group rather than combining it with the wildcard group. Google documents this group selection in its robots.txt specification guidance.

Use the longest matching path

Within the applicable group, compare every Allow and Disallow path that matches the requested URL path. The rule matching the most characters is the most specific.

User-agent: *
Disallow: /private/
Allow: /private/public-example/

The path /private/public-example/page matches both rules. The longer Allow rule wins, so the crawler is allowed to request that path.

The standardized Robots Exclusion Protocol defines this most-specific-match behaviour in RFC 9309.

Allow wins an equal-length conflict

When an Allow and Disallow rule match the same number of characters, the Allow rule is used under the RFC model. Google describes the same least-restrictive result for equal rules.

Rule order is therefore not a reliable way to resolve a tie. Make the intended exception explicit and test the exact path.

Wildcards and end anchors need care

Google supports * as a wildcard and $ as an end-of-path marker in rule values. A pattern such as /*.pdf$ is narrower than a plain / block, but small punctuation changes can alter which paths match.

Crawler implementations are not identical. Test named crawlers against the syntax they document rather than assuming every agent supports every extension.

No matching rule normally means allowed

An empty Disallow value does not block the site. When no applicable Allow or Disallow path matches, crawling is normally allowed.

That does not guarantee that the crawler will visit the page. It only means this robots.txt evaluation did not prohibit the request.

What a robots test cannot prove

A deterministic tester can identify the applicable group, matching rule, and resulting Allow or Disallow decision for the text it receives. It cannot prove that a crawler will visit, render, index, cite, or rank the page.

Robots.txt is also not authentication. The file is public, and disallowed URLs can still be discovered from links. Google’s robots.txt introduction warns against using it to keep web pages out of Search or to protect sensitive information.

A safe rule-testing workflow

  1. Name the exact crawler you want to test.
  2. Use the URL path, including relevant query text when the crawler’s syntax supports it.
  3. Test the current live file and any proposed replacement separately.
  4. Record the selected group and exact matching rule.
  5. Check important public paths as well as intended blocked paths.
  6. Deploy the file at the site root as /robots.txt.
  7. Fetch the public file and repeat the same tests.

Use the free Robots.txt Tester to evaluate a named crawler and path against live or pasted rules.

Method note: the tester uses deterministic group and longest-path matching for the supplied crawler and rules. It reports policy evidence, not crawler behaviour or indexing. Last reviewed 23 August 2026.

Overhyped Robots.txt Tester evaluating a named crawler and path against pasted Allow and Disallow rules
A focused view of the free Robots.txt Tester. Test a crawler path
Continue learning

Keep moving with a closely related topic and a free tool you can use immediately.

Watercolor illustration of several webpage paths converging on one preferred page with a coral link symbol

How to Check a Canonical URL Without Guessing

Learn what a canonical tag communicates, how to compare it with the final URL, and which conflicts need review before you change the page.

Watercolor illustration of a hand arranging abstract rule strips into a robots file beside a crawler path and coral check seal

How to Create a Safe Robots.txt File

Start with a small crawler policy, add only intentional path restrictions, test exceptions, and verify the public file before relying on it.

Watercolor illustration contrasting a winding chain of webpage hops with one direct coral route to the final page

How to Find and Fix Redirect Chains

Trace each redirect hop, choose the right permanent or temporary response, and update links so visitors and crawlers reach the final URL directly.