How to Create a robots.txt File (With Examples)
What robots.txt does and does not do, how Google matches rules (one group per crawler, longest path wins), the same file read by two parsers with different answers, and what research and our own analytics say about blocking AI crawlers.
What robots.txt Does, and What It Does Not
robots.txt tells crawlers which URLs they may fetch. Google's own introduction is blunt about the limits: it is used mainly to avoid overloading a site with requests, and it is not a mechanism for keeping a page out of Google. A blocked URL can still be indexed without its content if other pages link to it; to keep a page out of results, let it be crawled and use noindex, or put it behind a password. And because the file is public and voluntary, it is no protection for anything private.
The file lives at the root of each host, and each protocol and subdomain needs its own: https://example.com/robots.txt says nothing about https://shop.example.com/. Google reads the first 500 KiB and ignores the rest. How the server answers matters too:
| robots.txt answers with | What Google does |
|---|---|
| 200 and a file | Follows the rules in it |
| 404 or another 4xx (except 429) | Assumes there are no crawl restrictions |
| 5xx server error | Stops crawling the site for the first 12 hours, then uses the last good copy for up to 30 days while retrying |
So a site with nothing to block does not need a robots.txt at all, though one that lists your sitemap is still useful. A robots.txt that starts throwing server errors, on the other hand, can pause crawling of everything.
Syntax and How Rules Are Matched
User-agent: *
Disallow: /admin
Allow: /admin/public
Disallow: /*?print
Disallow: /*.pdf$
Disallow: /search
User-agent: Googlebot
Disallow: /private
Sitemap: https://example.com/sitemap.xml
Each group starts with one or more User-agent lines followed by Allow and Disallow rules. The rules Google applies, from its robots.txt documentation (updated August 31, 2026) and RFC 9309:
- Only one group applies to a crawler: the one with the most specific matching user agent. In the file above, Googlebot obeys only its own group, so
/adminis open to Googlebot even though the*group blocks it. This is the rule people most often miss. - The longest matching path wins, whatever the order of the lines.
Allow: /admin/publicbeatsDisallow: /adminfor/admin/public/page. On a tie, Google uses the less restrictive rule. - Rules are prefixes.
Disallow: /searchalso blocks/search-tips. Add a trailing slash (/search/) to mean only the directory. *matches any sequence of characters and$anchors the end, so/*.pdf$blocks PDF files but notreport.pdf?v=2.- Paths are case-sensitive:
/Admin/is not/admin/. Crawl-delayis ignored by Google; other crawlers may honor it. TheSitemapline takes an absolute URL and applies to every group.
Same File, Different Answers
A robots.txt is only as good as the parser reading it. We ran the file above through two Python parsers on October 13, 2026: urllib.robotparser from the standard library, and Protego, the parser Scrapy uses, which follows RFC 9309 and Google's matching rules.
| Crawler | URL | urllib.robotparser | Protego (Google-style rules) |
|---|---|---|---|
| OtherBot | /admin/settings | blocked | blocked |
| OtherBot | /admin/public/page | blocked | allowed |
| OtherBot | /article?print=1 | allowed | blocked |
| OtherBot | /files/report.pdf | allowed | blocked |
| OtherBot | /files/report.pdf?v=2 | allowed | allowed |
| OtherBot | /search-tips | blocked | blocked |
| OtherBot | /Admin/settings | allowed | allowed |
| Googlebot | /admin/settings | allowed | allowed |
| Googlebot | /private/notes | blocked | blocked |
They disagree on 3 of 9 URLs. The standard-library parser takes the first rule that matches instead of the longest, so it blocks /admin/public/page, and it does not understand * or $, so it lets through the print and PDF URLs the file meant to block. Both agree on the traps that are in the rules themselves: /search-tips is caught by the /search prefix, and Googlebot ignores the * group. If you check a robots.txt in code, use a parser that implements RFC 9309, such as Protego or Google's own open-source C++ parser.
AI Crawlers
Since 2023 robots.txt has also become the main way to say no to AI training. Longpre and colleagues (the Data Provenance Initiative, 2024) audited 14,000 web domains behind three large AI training corpora and found that within one year, April 2023 to April 2024, robots.txt rules went from fully restricting about 1% of the tokens in those corpora to 5 to 7%, and 20 to 33% of the most important sources. OpenAI's crawlers were the most restricted, blocked for 25.9% of tokens in the most important part of C4, against 1.0% for Google's search crawler.
Their audit also shows how easily the wrong name gets blocked: 4.5% of sites disallowed anthropic-ai or Claude-Web, user agents Anthropic does not use, while leaving its documented crawler, ClaudeBot, untouched. Take agent names from each company's own documentation. OpenAI, for example, documents separate crawlers for separate purposes: OAI-SearchBot for search results and GPTBot for training, and says each setting is independent, so a site can stay findable in ChatGPT search while declining training.
That distinction matters in practice. Our robots.txt allows every crawler, and in the 28 days to October 7, 2026 our analytics recorded 341 visits referred by ChatGPT against 50 from Google search. A blanket block on OpenAI's agents would have cut our second-largest source of real visitors.
Testing Your File
Search Console's robots.txt report shows the robots.txt files Google found for your site, when it last fetched each one, whether the fetch succeeded and any rules it could not parse, and lets you request a recrawl after an urgent fix. For individual URLs, run the file through an RFC 9309 parser as in the table above, or use your crawler's documentation for its specific rules.
Our Robots.txt Generator writes the file and normalizes what you type to the standard: it adds the leading slash a path needs, encodes spaces, requires an absolute sitemap URL and lists every change it made. It does not test URLs against the result, so check important paths with a parser before you publish.
Frequently Asked Questions
What is robots.txt?
Does robots.txt prevent pages from being indexed?
Where do I put robots.txt?
Use the Robots.txt Generator โ free, no signup required.
โก Open Robots.txt Generator- [1]IETF RFC 9309, Robots Exclusion Protocol (2022) โ
- [2]Google, How Google interprets the robots.txt specification (updated Aug 31, 2026) โ
- [3]Google Search Central, Introduction to robots.txt (updated Dec 10, 2025) โ
- [4]Google Search Console Help, robots.txt report, checked Oct 13, 2026 โ
- [5]Google, open-source robots.txt parser (C++) โ
- [6]Protego, RFC 9309 robots.txt parser used by Scrapy โ
- [7]Python documentation, urllib.robotparser โ
- [8]OpenAI, Overview of OpenAI crawlers (GPTBot, OAI-SearchBot, ChatGPT-User), checked Oct 13, 2026 โ
- [9]Longpre et al. (2024), Consent in Crisis: The Rapid Decline of the AI Data Commons, found via alphaXiv โ