Robots.txt is a plain text file at the root of your site that tells crawlers which URLs they're allowed to fetch. Google's documentation defines its job narrowly: managing crawler traffic, "mainly to avoid overloading your site with requests". It controls crawling, not indexing, and nearly every expensive robots.txt mistake comes from confusing those two jobs. This guide covers how the file works, what belongs in it, what never does, and how to handle the new generation of AI crawlers.
I have a personal stake in this topic. The site you're reading launched with Disallow: / in its robots.txt, a leftover from pre-launch, and sat invisible to every search engine until I caught it. One line. That's all it takes, in either direction, which is why this file deserves fifteen minutes of actual understanding instead of a copied snippet from a forum.
What Robots.txt Actually Is
One file, one location: https://yourdomain.com/robots.txt. Crawlers request it before crawling anything else on the host, read the rules that apply to their user agent, and, if they're well-behaved, respect them. A complete, healthy robots.txt for a typical small site is three lines:
User-agent: *
Disallow:
Sitemap: https://example.com/sitemap.xml
That says: every crawler, nothing blocked, and here's the sitemap. An empty Disallow means "allow everything". This site runs exactly that file, and you can read it live. Most small sites never need more.
Worth knowing where the rules come from: the protocol was invented by Martijn Koster in 1994 and ran on convention for decades before becoming a formal standard, RFC 9309, in September 2022. That history explains its quirks: it's simple, it's voluntary, and different crawlers interpreted it differently for years.
The Distinction That Prevents Disasters: Crawling vs Indexing
Robots.txt answers one question: may a crawler fetch this URL? It says nothing about whether the URL appears in search results. Google's robots.txt introduction is blunt about it: robots.txt "is not a mechanism for keeping a web page out of Google."
It gets more counterintuitive. A page blocked by robots.txt can still get indexed. If other sites link to the blocked URL, Google may index the address itself, showing it in results with no description, because it knows the page exists without being allowed to read it. And the trap inside the trap: a noindex tag on a robots-blocked page does nothing, because Google can't crawl the page to see the tag.
How Google Reads Your File
A handful of behaviors, all documented in Google's robots.txt specification, explain most of the "why is it ignoring my rules" confusion:
- One file per host, protocol and port. The rules in
https://example.com/robots.txtdon't coverblog.example.comor the http version. Every subdomain needs its own file. - Paths are case-sensitive.
Disallow: /Private/doesn't block/private/. Field names like User-agent don't care about case; path values do. - It's cached up to 24 hours. Fixing the file doesn't take effect the moment you save. Give it a day before judging.
- A missing file means "crawl everything". 4xx responses for robots.txt are treated as if no file exists. Deleting a broken robots.txt is a valid emergency fix.
- A 5xx error freezes crawling. If your server errors when serving robots.txt, Google initially stops crawling the whole site for 12 hours, then falls back to a cached copy for up to 30 days. A misconfigured server rule on this one file can quietly pause your entire crawl.
- 500 KiB is the ceiling. Content past that gets ignored. If your robots.txt is anywhere near it, something upstream has gone very wrong.
The Syntax That Matters
Google supports exactly four fields. Everything else in your file is decoration:
| Directive | What it does | Google's treatment |
|---|---|---|
| User-agent | Names the crawler the following rules apply to. * matches all | Supported. Most specific matching group wins |
| Disallow | Path prefix the crawler may not fetch | Supported. Empty value allows everything |
| Allow | Exception that re-opens a path inside a disallowed one | Supported. More specific rule wins over shorter one |
| Sitemap | Absolute URL of your sitemap, any number of lines | Supported. Works for every crawler that reads the file |
| Crawl-delay | Seconds between requests, in theory | Not supported. Google ignores it entirely |
Two wildcards make paths flexible: * matches any run of characters, and $ pins the end of a URL. A few worked examples:
# Block internal search results pages
Disallow: /search
# Block every URL containing a query string
Disallow: /*?
# Block PDFs only, wherever they live
Disallow: /*.pdf$
# Block a folder but allow one file inside it
Disallow: /assets/
Allow: /assets/logo.png
Remember these are prefix matches: Disallow: /search blocks /search, /search/anything and /searchable-page too. When a rule catches more than you intended, that last behavior is usually why.
What to Block, and What to Leave Alone
The test for every Disallow line: does crawling this URL waste the crawler's time without any chance of useful indexing? If yes, block it. If you're blocking because you don't want the page seen, you want a different tool.
Sensible to block
- Internal search result pages
- Faceted filter and sort URL explosions
- Cart, checkout and account paths
- Infinite spaces: calendars, session IDs, print views
- Staging sites, as a backup behind real authentication
Never block
- CSS and JavaScript files your pages need to render
- Pages you want removed from results (that's noindex)
- Private or sensitive content (that's authentication)
- Pages carrying a noindex tag you need Google to read
- Your whole site, out of caution, "temporarily"
The CSS and JavaScript one deserves its sentence: Google renders pages like a browser, and if robots.txt blocks the files that build the layout, Google sees a broken page and judges it accordingly. Old WordPress advice to block /wp-includes/ aged badly for exactly this reason.
The AI Crawlers: New Tokens, Same File
Robots.txt found a second life as the opt-out switch for AI training. The major AI companies publish user agent tokens and state they respect the file. The ones that matter in practice:
| Token | Company | Blocking it affects |
|---|---|---|
| GPTBot | OpenAI | Training data collection for GPT models |
| OAI-SearchBot | OpenAI | ChatGPT search results and citations of your site |
| ClaudeBot | Anthropic | Training data collection for Claude models |
| PerplexityBot | Perplexity | Perplexity's search index and citations |
| Google-Extended | Gemini training and grounding. Not Google Search |
Two facts before you block anything. First, per Google's crawler documentation, Google-Extended "does not impact a site's inclusion in Google Search nor is it used as a ranking signal". AI Overviews ride normal Google indexing, so blocking Google-Extended won't pull you out of them. Second, compliance is voluntary: reputable companies honor these rules, scrapers never did.
Whether to block is a business decision, not a technical one. For a business site like mine, AI assistants citing my content is free distribution, so I block nothing. A publisher selling the content itself may reason differently. Decide from your model, then write the three lines.
Which Tool Do You Actually Need?
Say what you're trying to accomplish, and get the right mechanism. This runs entirely in your browser.
Add a noindex meta tag or X-Robots-Tag header, and make sure robots.txt does NOT block the page, or Google never sees the tag. Full directive reference in my meta tags guide.
This is exactly what the file is for: search results pages, filter explosions, carts, infinite calendars. Write the narrowest pattern that catches the junk, test it, and check the templates below.
Robots.txt is public and only stops polite bots, so listing private paths there advertises them. Put sensitive content behind a login or HTTP auth. Then robots.txt becomes irrelevant, which is the point.
Disallow rules for GPTBot, ClaudeBot, PerplexityBot and Google-Extended, knowing compliance is voluntary and Google Search is unaffected. Weigh the tradeoff first: AI crawlers section above.
The Mistakes I Keep Finding on Audits
- The staging block that shipped.
Disallow: /goes live with the redesign, and traffic bleeds out silently. It happened to this very site at launch. Make "check robots.txt" a deployment step, not an incident response. - Robots.txt as a privacy tool. The file is publicly readable. Listing
/admin/or/internal-reports/hands every curious visitor a map of what you consider sensitive, while blocking only the bots polite enough to ask. - Blocking a page and noindexing it. The block stops Google from ever reading the noindex, so the URL can linger in results anyway. Pick one mechanism per goal.
- Blocking rendering assets. CSS and JS behind a Disallow turn your pages into broken skeletons in Google's eyes, and mobile-friendliness checks fail for no visible reason.
- Forgetting subdomains are separate. The main site's file doesn't cover blog., shop. or staging. subdomains. Each host answers for itself.
- Overreaching prefixes.
Disallow: /pagealso kills/pages/pricing. Prefix matching plus wildcards means every rule deserves a test against real URLs before it ships. - The file that errors. A server rule that 5xxes on robots.txt can freeze crawling of the whole site for days. If nothing else, make sure this one URL always returns 200 or 404, never 500.
Testing Your File
Three checks, thirty seconds each:
- Fetch it like a crawler would. Open
yourdomain.com/robots.txtin an incognito window, or from a terminal:
curl -sI https://example.com/robots.txt # status must be 200 (or 404 if you have no file)
curl -s https://example.com/robots.txt # read what crawlers actually receive
- Check what Google has. Search Console's robots.txt report (under Settings, Crawling) shows the fetched file, when it was fetched, and parse errors. This is Google's copy, cache and all, not your server's.
- Test specific URLs. Run your important pages through URL Inspection. "Blocked by robots.txt" on a money page is the finding that pays for the whole exercise. My indexing guide covers what to do with every verdict.
Copy-Paste Templates
Three starting points covering most real situations. Adjust paths to your site before shipping:
User-agent: *
Disallow:
Sitemap: https://example.com/sitemap.xml
User-agent: *
Disallow: /search
Disallow: /cart
Disallow: /checkout
Disallow: /*?sort=
Disallow: /*?filter=
Sitemap: https://example.com/sitemap.xml
User-agent: GPTBot
Disallow: /
User-agent: ClaudeBot
Disallow: /
User-agent: Google-Extended
Disallow: /
User-agent: *
Disallow:
Sitemap: https://example.com/sitemap.xml
The Robots.txt Checklist
Run this on your live file today
- File lives at the root and returns 200 (or intentionally 404)
- No Disallow: / unless you genuinely mean to vanish
- CSS, JS and images needed for rendering are not blocked
- Nothing sensitive is "protected" by a Disallow line
- No page is both robots-blocked and noindexed
- Every rule tested against real URLs, prefixes checked
- Sitemap line present with the absolute URL
- Every subdomain has its own correct file
- AI crawler policy decided deliberately, not by default
- Search Console's robots.txt report shows no parse errors
Not Sure What Your Robots.txt Is Costing You?
A wrong line in this file is invisible until the traffic graph tells you. I check robots.txt, indexing, canonicals and the whole crawl path in my free audit, personally, and tell you what I'd fix first.
Get My Free Audit