Reference guide · technical-seo · Published 2026-08-16 · 4 min read

Advanced robots.txt directives

Advanced robots.txt syntax: wildcards and dollar anchors, user-agent groups and longest-match, the Sitemap line, and the crawl-vs-index split.

The full grammar

The robots.txt basics cover User-agent, Allow, Disallow and the general shape. The advanced surface adds three things: wildcards, the dollar anchor, and the Sitemap line being a separate, non-rule field.

Wildcards and the dollar

User-agent: *
Disallow: /private/*.pdf$
Allow: /private/guide$

The Sitemap: line

Sitemap: is not a rule. It is a hint to crawlers about where the XML sitemap lives, and it is not subject to User-agent groups (search engines ignore a Sitemap: inside a group aimed at a different bot). The exact text from the engines: the sitemap field is not tied to any specific user agent. The value must be a fully qualified absolute URL (https://example.com/sitemap.xml). It is case-sensitive in the URL part, and you can repeat it (one per sitemap).

Longest-match and matching

Google's guide describes the "longest match" rule precisely: a matcher that includes a path up to the first wildcard, or a "word boundary" (the $ or the end-of-the-URL), whichever comes first. A rule such as Disallow: /forum/* matches any URL starting /forum/. The classic subtlety is that a match is a prefix match of the URL path, not of the whole file, so Disallow: /private matches /private, /private/ and /private-key (the reverse is not implied), and Allow: /private/ does not allow /private-key.

Group matching and precedence

Rules apply to the most specific (longest) matching rule for the URL among those in a matching user-agent group. Order in the file matters only when two rules within the same group match the same length; otherwise the longer (more specific) route wins, so a /public Allow can override the broader / Disallow. Groups are independent. English defaults: no rules means everything is allowed; a Disallow: with an empty value means allow all within that group.

The key differences between the group-level and URL-level reality:

The indexing boundary (meta robots vs x-robots vs robots.txt)

The three controls form the complete indexing story:

The one rule that confuses everyone: robots.txt can block, but cannot cause a page to be *removed*. Google's model: if a URL can be discovered while robots.txt disallows crawling it, the URL can stay in the index with limited data. To remove, use the HTML or header noindex.

When advanced robots.txt matters

Clarity beats cleverness: a single Sitemap: line at the footer, a few broad Disallows, and understanding that the meta/X header owns indexing will outperform a "clever" 200-line robots.txt with 40 wildcard combos. The noindex meta article is the pairing that turns robots.txt into a complete deindexing policy.

Need a website built, fixed, optimised, migrated or replaced?

This technical resource is written by CSMBAC, a small design and development studio. If you would rather hand the problem to a professional, the website service page explains how we build enquiry-ready websites.

Explore website services