Sub topic 5
Controlling access with robots.txt
This chapter assumes you know how web crawlers fetch pages, can read basic HTTP status codes, and have edited a plain-text file on a web server. It builds on the previous chapter's split between search, training, and user-initiated crawlers. Here you will turn that split into rules in robots.txt, and learn where those rules stop working.
What robots.txt does and does not do
robots.txt is a plain-text file served at the root of a host, for example https://www.example.com/robots.txt. It follows the Robots Exclusion Protocol (RFC 9309). Crawlers fetch it before fetching other URLs on that host and decide what they may request.
Three properties shape everything else in this chapter:
- It is a request, not enforcement. Well-behaved crawlers honor it. Nothing in the protocol stops a client that ignores it.
- It controls crawling, not indexing or citation by itself. A blocked URL can still appear in an index as a bare link if other pages point to it, depending on the engine.
- It applies per host and per protocol and port.
blog.example.comneeds its own file, separate fromwww.example.com.
For answer engines, this matters because each crawler you allow or block feeds a different stage of the pipeline. Blocking a search crawler removes your pages from that engine's index. Blocking a training crawler only affects future model training.
How rules are matched
A file is a list of groups. Each group starts with one or more User-agent lines and is followed by Allow and Disallow rules.
User-agent: OAI-SearchBot
Allow: /
User-agent: GPTBot
Disallow: /The matching rules that cause most mistakes:
- A crawler uses the single group with the most specific matching
User-agenttoken. It does not merge that group with the*group. - Within a group, the longest matching path wins. If an
Allowand aDisallowmatch with equal length, the less restrictive rule (Allow) wins. - Paths are case-sensitive and match from the start of the URL path.
Disallow: /privatealso blocks/private-notes. - User-agent tokens are case-insensitive.
- An empty
Disallow:means nothing is disallowed.
Rule 1 is the common trap. Suppose you write this:
User-agent: *
Disallow: /drafts/
User-agent: PerplexityBot
Allow: /PerplexityBot follows only its own group, so /drafts/ is now crawlable by it. If you want it excluded, repeat the rule in its group.
Setting rules per crawler type
The previous chapter separated three kinds of agents. Map each to a policy decision:
| Purpose | Example tokens | Effect of blocking |
|---|---|---|
| Search indexing | `OAI-SearchBot`, `PerplexityBot`, `bingbot` | Pages drop out of that engine's index and of answers built from it |
| Model training | `GPTBot` | Content is not used for training; search visibility is unaffected |
| User-initiated fetch | `ChatGPT-User`, `Perplexity-User` | May stop a fetch triggered when a user asks the assistant to read your page |
A configuration that stays eligible for answer-engine search while declining training use looks like this:
# Allow the crawler that builds ChatGPT's search index
User-agent: OAI-SearchBot
Allow: /
# Opt out of model training use
User-agent: GPTBot
Disallow: /
# Allow Perplexity's search crawler
User-agent: PerplexityBot
Allow: /
# Allow Bing, whose index Copilot draws on
User-agent: bingbot
Allow: /Copilot has no crawler of its own in this list. It relies on Bing's index, so bingbot is the token that governs your Copilot visibility.
Rather than a diagram of the file, the decision flow below shows how a crawler resolves your rules.
Failure modes and edge cases
Status codes on robots.txt itself
How the file is served changes behavior:
- A
200response means the rules apply as written. - A
404is generally treated as "no restrictions", so everything is crawlable. - A
5xxor a timeout is treated by many crawlers as "unknown", and they may pause crawling or treat the whole site as disallowed. Under RFC 9309, a crawler should assume complete disallow while the file is unreachable because of a server error.
A flaky robots.txt can therefore remove you from an index without any rule being wrong. Monitor that URL like any other critical endpoint.
Caching and delay
Crawlers cache your file, often for up to 24 hours. A rule change is not instant. After you edit it, expect a delay before the new behavior appears in your logs, and expect pages already indexed to persist for a while after you add a Disallow.
User-initiated fetchers may not follow the same rules
Some vendors state that agents acting on a user's direct request (such as ChatGPT-User) are not automated crawlers, so robots.txt may not govern them the same way. Policies change between vendors and over time. Read each vendor's current documentation instead of assuming the behavior from the table above.
Blocking is not removal
Adding Disallow stops future crawling. It does not delete content already stored in an index or already used for training. To remove a page, use the engine's removal tools, a noindex directive on a page the crawler can still fetch, or an HTTP 404/410. Note the interaction: if you block a URL in robots.txt, the crawler cannot see a noindex tag on it, so the tag has no effect.
Spoofed and non-compliant agents
Anyone can send a request with User-Agent: GPTBot. If a rule matters for security or cost, do not rely on the user-agent string. Use the vendor's published IP ranges, reverse DNS checks, or a web application firewall to verify the source, and use authentication for content that must stay private.
Testing your file
Check a few things after every change:
- Fetch the file directly and confirm a
200status and the plain-text content type. - Confirm each token is spelled exactly as the vendor documents it.
- Test representative URLs against the group each crawler will use.
- Watch your access log over the next days to confirm the expected crawlers appear and blocked ones stop. The measuring chapter covers log analysis in detail.
You can parse the file and test URLs yourself with Python's standard library:
from urllib.robotparser import RobotFileParser
rules = """\
User-agent: GPTBot
Disallow: /
User-agent: OAI-SearchBot
Allow: /
"""
parser = RobotFileParser()
parser.parse(rules.splitlines())
url = "https://www.example.com/guide"
for agent in ["GPTBot", "OAI-SearchBot", "PerplexityBot"]:
print(agent, parser.can_fetch(agent, url))This prints False for GPTBot, True for OAI-SearchBot, and True for PerplexityBot, because no group matches it and no * group exists, so nothing is restricted. Python's parser applies rules in file order rather than longest-match, so it can disagree with Google-style matchers on complex files. Treat it as a quick check, not as proof of how every crawler behaves.
Decision criteria
Choose a policy by what you want from each stage:
- You want citations and referrals: allow the search crawlers of each engine. This is necessary but not sufficient, since being crawlable does not guarantee being cited.
- You object to training use but want visibility: block training tokens and allow search tokens, as shown above.
- You want no AI exposure: block all the tokens, and accept that Copilot visibility also depends on
bingbot, which you may not want to block because it also serves ordinary Bing search. - You have mixed content: use path-level rules, for example
Disallow: /members/inside each relevant group, and remember to repeat shared rules in every group.
Exercise
Your file has a User-agent: * group with Disallow: /drafts/ and a separate User-agent: PerplexityBot group with only Allow: /. Can PerplexityBot fetch /drafts/post-1? Explain, and give the fix.
Show answer
Yes, it can. PerplexityBot uses only its own group and ignores the * group, so the /drafts/ rule does not apply to it. Fix it by adding Disallow: /drafts/ to the PerplexityBot group.
Exercise
You add Disallow: /old-page to robots.txt and a <meta name="robots" content="noindex"> tag to that page, hoping to remove it from an index. Why might it stay listed?
Show answer
The crawler is blocked from fetching the page, so it never sees the noindex tag. Remove the Disallow rule so the crawler can fetch the page and read noindex, or return a 404 or 410 status.