Articles
Published · November 18, 2026

robots.txt Syntax: User-agent, Allow, and Disallow Explained

A robots.txt file is plain text: User-agent lines name a crawler, and Disallow and Allow lines list the paths it may skip or fetch. Here is how the rules are read.

Also in: Español中文हिन्दी

A robots.txt file is a plain-text list of rules that tells crawlers which paths on your site to skip. Each rule sits in a group that starts with a User-agent line, followed by Disallow and Allow lines. The format is short. A few details still decide whether a rule works: where the file lives, how groups are read, and which rule wins when two match.

Where the file lives and how it is encoded

The file must be named robots.txt, in lowercase, at the top level of the site. RFC 9309, the IETF standard for the Robots Exclusion Protocol, says it must be UTF-8 encoded and served as text/plain.

Scope matters here. A robots.txt file covers one origin: each subdomain, URI scheme, and port needs its own file. The file at http://example.com/robots.txt does not apply to https://example.com/. If the file does not exist, crawlers assume you have placed no limits.

User-agent lines and groups

The unit of robots.txt is the group. RFC 9309 defines it as one or more User-agent lines followed by one or more rules. A group ends at the next User-agent line or at the end of the file.

User-agent: examplebot
Disallow: /drafts/

User-agent: *
Disallow: /tmp/

Here examplebot follows the first group. Every other crawler falls back to the * group. A few matching details from the RFC:

  • A crawler matches its product token against User-agent values case-insensitively. Product tokens use only letters, underscores, and hyphens.
  • If no group matches, the crawler must use the * group when there is one.
  • If there is no match and no * group, no rules apply.
  • Several User-agent lines can share one set of rules, so you do not need to repeat them.

Disallow and Allow rules

A rule is a path prefix. Matching starts at the first character of the URL path, so Disallow: /drafts/ covers /drafts/ and everything under it.

User-agent: *
Disallow: /drafts/
Allow: /drafts/public/

Three defaults to remember:

  • A URL that matches no rule is allowed.
  • An empty Disallow: line blocks nothing.
  • Disallow: / blocks the whole site. MDN's robots.txt guide shows this as the way to stop all search engines from crawling a site.

The /robots.txt file itself is implicitly allowed, so a crawler can always read it.

Wildcards, end anchors, and comments

RFC 9309 requires crawlers to support three special characters:

  • * matches zero or more of any character.
  • $ marks the end of the URL.
  • # starts a comment, either on its own line or after a directive.
# keep crawlers out of PDF exports
User-agent: *
Disallow: /exports/*.pdf$

Wikipedia's example makes the wildcard concrete: Disallow: /something/*/other blocks /something/foo/other but not /something/foo/else. The same page notes that a wildcard at the very end of a rule does nothing, since rules are already prefix matches.

These characters work differently from the ones in a gitignore file, so do not carry habits from one format to the other. In robots.txt every rule is a prefix, and there is no negation line.

Two other lines show up often but sit outside the core standard. Sitemap: <full URL> is supported by some crawlers and may appear several times. Crawl-delay is read differently by each crawler, and per Wikipedia, Google ignores it.

Which rule wins

When more than one rule matches a URL, the most specific one wins. RFC 9309 defines that as the match with the most octets, which in practice means the longest path. If an Allow and a Disallow match with equal length, the Allow should be used.

The RFC's own example pairs Allow: /example/page/ with Disallow: /example/page/disallowed.gif. The longer Disallow wins for disallowed.gif, while the rest of /example/page/ stays allowed.

Paths should be matched case-sensitively, so /Admin/ and /admin/ are different rules. Non-ASCII and reserved characters are percent-encoded before comparison.

What robots.txt is not

The rules are requests, not locks. RFC 9309 states that they are not a form of access authorization, and Wikipedia calls the protocol purely advisory. MDN adds that the file is publicly readable, so listing a sensitive path shows its location to anyone who looks. Some robots, such as malware bots and email harvesters, ignore it entirely.

Use real authentication for anything private. Use robots.txt to manage crawl load and to keep low-value paths out of search results.

How crawlers handle problems is also specified:

  • A 4xx response means the file is unavailable, and the crawler may access any resource.
  • A 5xx response means the file is unreachable, and the crawler must assume everything is disallowed.
  • Crawlers must parse at least 500 kibibytes, and should not use a cached copy for more than 24 hours unless the file is unreachable.

Editing the file by hand

Because robots.txt is just text, any editor can change it. Small slips have large effects, though: a stray Disallow: / can hide a whole site from crawlers. Keep the file in UTF-8, put one directive per line, and review it before you deploy. A project-wide settings file such as an EditorConfig file can keep line endings and indentation consistent, and our note on mixed-language UTF-8 text files covers encoding pitfalls.

How Carets fits in

Carets is a native notes and code editor for iPhone, iPad, and Mac that handles plain text, Markdown, and code in one place. For a file like robots.txt, that helps in practical ways:

  • Plain-text editing keeps the file exactly as you typed it, with no rich-text formatting added.
  • Syntax highlighting for config files makes comments and directives easier to scan.
  • Files, projects, and tags let you keep a site's robots.txt next to its other config files and notes.

You can fix a rule from your iPhone or Mac and skip the full IDE. Download Carets for iPhone, iPad, and Mac from the App Store.

Frequently Asked Questions

Does robots.txt hide a page from search results?

No. It asks crawlers not to fetch a path. It is advisory, and the path itself is public in the file. Use authentication to protect content.

Are robots.txt rules case sensitive?

Paths should be matched case-sensitively, so /Admin/ and /admin/ are different. User-agent names are matched case-insensitively.

What happens if my robots.txt returns an error?

Per RFC 9309, a 4xx response means the crawler may access anything, and a 5xx response means it must assume everything is disallowed.