A robots.txt file is a plain text file at the top of a website, such as https://example.com/robots.txt, with rules for automated crawlers. Before a well-behaved crawler fetches pages from a site, it reads this file and skips the URLs the rules tell it to avoid.
The rules follow the Robots Exclusion Protocol, which Martijn Koster proposed in 1994. After almost three decades of informal use, it became an internet standard in September 2022 as RFC 9309.
What robots.txt can and can't do
Robots.txt controls crawling: which URLs a crawler fetches. You use it to keep crawlers away from pages that waste their time and your server's, such as internal search results, endless filter combinations or staging copies. That's also how it helps your crawl budget on large sites.
It doesn't control indexing. If other pages link to a URL you've blocked, Google can still index that URL without visiting it. The result then shows up without a description. To keep a page out of search results, use a noindex rule or put the page behind a password.
Don't combine the two on one page. A crawler that's blocked from a page never sees its noindex rule, so the page can stay in results. Google also ignores noindex lines inside robots.txt.
Robots.txt isn't security either. RFC 9309 says plainly that the rules are not a form of access authorization. Reputable crawlers follow them; others ignore them. And because the file is public, listing a secret folder in it tells everyone where to look.
One exception for media: blocking image, video and audio files in robots.txt does keep them out of Google's results.
Where the file goes
The file must sit at the root of the host and be named robots.txt in lowercase. Its rules apply only to that exact host, protocol and port:
https://example.com/robots.txtcovershttps://example.com/and everything below it.- It doesn't cover
https://shop.example.com/orhttp://example.com/. Each subdomain and protocol needs its own file.
If there's no file, crawlers assume they can fetch everything.
How to write the rules
A robots.txt file is made of groups. Each group starts with one or more user-agent lines naming the crawlers it's for, followed by disallow and allow rules:
# Keep all crawlers out of internal search and the cart
User-agent: *
Disallow: /search
Disallow: /cart/
Allow: /search/help
# Keep one crawler out of the whole site
User-agent: ExampleBot
Disallow: /
Sitemap: https://example.com/sitemap.xml
- User-agent names a crawler by its token, such as
GooglebotorBingbot.*means every crawler without a group of its own. A crawler follows only the one group that names it most specifically and ignores the rest. See user agent. - Disallow gives a path the crawler shouldn't fetch.
Disallow: /blocks the whole site; an emptyDisallow:blocks nothing. - Allow opens up a path inside a disallowed one.
- Sitemap gives the full URL of your sitemap. It applies to all crawlers, and you can list several.
Paths are case-sensitive and match from the start of the URL path, so Disallow: /cart/ also blocks /cart/checkout. Google and Bing support two wildcards: * matches any run of characters, and $ marks the end of the URL. Disallow: /*.pdf$ blocks every URL ending in .pdf.
When an allow and a disallow rule both match a URL, Google uses the more specific one, meaning the longer path. If they're equally specific, it picks the less restrictive rule, allow (Google's robots.txt spec). Other crawlers may resolve conflicts differently, so avoid rules that depend on fine distinctions.
Google ignores crawl-delay. Bing said in 2012 that Bingbot honors it, reading the value as a window of 1 to 30 seconds in which it fetches at most one page (Bing Webmaster Blog).
Blocking AI crawlers
AI companies publish their own crawler tokens, so you can decide separately about search and AI training:
- Google-Extended controls whether content Google crawls may be used to train Gemini models and for grounding answers. Blocking it doesn't affect your inclusion or ranking in Google Search.
- GPTBot is OpenAI's crawler for training data. OAI-SearchBot is the one that finds pages for ChatGPT's search answers. OpenAI treats the two independently, and a site that blocks OAI-SearchBot won't be shown in ChatGPT search answers.
To refuse training but stay in ChatGPT search:
User-agent: GPTBot
Disallow: /
User-agent: OAI-SearchBot
Allow: /
Check each company's own crawler page before you write rules: tokens change, and a fetcher that visits a page because a user asked for it may not follow robots.txt. OpenAI says this of its ChatGPT-User agent.
What Google does when the file is missing or broken
The server's response for robots.txt changes how Google crawls:
| Response | What Google does |
|---|---|
| 2xx (success) | Follows the rules in the file |
| 4xx, such as 404 (except 429) | Acts as if there's no file: crawls everything |
| 5xx or network errors | Stops crawling for 12 hours, then uses the last good copy for up to 30 days |
Google usually caches the file for up to 24 hours, so changes don't apply instantly. It reads only the first 500 KiB, and the file should be UTF-8 plain text.
Mistakes worth checking for
- A leftover
Disallow: /. Staging sites often block everything, and the rule sometimes survives the launch. - Blocked CSS or JavaScript. If Google can't load the files a page needs to render, it may misread the page.
- Robots.txt used to hide pages. Blocked URLs can still be indexed; use noindex.
- One file for several hosts. Each subdomain and protocol reads only its own file.
Test your file
Open /robots.txt on each host in a browser to see what crawlers see. In Google Search Console, the robots.txt report shows the files Google found for your top 20 hosts, when it last fetched them, and any errors. You can also ask Google to fetch a fixed file again. The report is available only for a Domain property or a URL-prefix property without a path, such as https://example.com/ (Search Console Help).