SEOMar 28, 2026 ยท Updated Oct 13, 2026 ยท 5 min read

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.

๐Ÿค–
Try the Robots.txt Generator
Free, no signup
โ†’
DG
Derek Giordano
Designer & Developer
In this guide
01What robots.txt Does, and What It Does Not02Syntax and How Rules Are Matched03Same File, Different Answers04AI Crawlers05Testing Your File

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 withWhat Google does
200 and a fileFollows the rules in it
404 or another 4xx (except 429)Assumes there are no crawl restrictions
5xx server errorStops 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:

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.

CrawlerURLurllib.robotparserProtego (Google-style rules)
OtherBot/admin/settingsblockedblocked
OtherBot/admin/public/pageblockedallowed
OtherBot/article?print=1allowedblocked
OtherBot/files/report.pdfallowedblocked
OtherBot/files/report.pdf?v=2allowedallowed
OtherBot/search-tipsblockedblocked
OtherBot/Admin/settingsallowedallowed
Googlebot/admin/settingsallowedallowed
Googlebot/private/notesblockedblocked

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?+
A text file at your domain root that tells search engine crawlers which URLs they should and shouldn't crawl. It controls crawl behavior, not indexing โ€” use noindex meta tags to prevent indexing.
Does robots.txt prevent pages from being indexed?+
No. It controls crawling, not indexing. If other sites link to a disallowed URL, Google may still index it without its content. To keep a page out of results, use a noindex robots meta tag or header, and do not block that page in robots.txt, or Google never fetches it and never sees the noindex.
Where do I put robots.txt?+
At the root of the host: https://example.com/robots.txt. A file in a subdirectory is ignored, and each subdomain and protocol needs its own file, so https://example.com/robots.txt does not cover https://shop.example.com/.
Try it yourself

Use the Robots.txt Generator โ€” free, no signup required.

โšก Open Robots.txt Generator
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.
โšก Try the free .htaccess Generator โ†’