What Is robots.txt? Syntax, Wildcards and AI Crawlers
What is robots.txt?
robots.txt is a plain-text file at the root of a website that tells crawlers which URL paths they may or may not request. Its rules, standardised in RFC 9309, are grouped by user-agent and use Allow and Disallow lines. It controls crawling, not indexing: a blocked URL can still appear in search results, so use noindex to keep a page out.
Where robots.txt lives and how crawlers read it
The Robots Exclusion Protocol was used informally from 1994 and published as an IETF standard, RFC 9309, in 2022. Key points from the standard and Google's documentation:
- The file must be at
/robots.txton the host, such as https://www.example.com/robots.txt. A file in a subfolder is ignored. - Each combination of protocol, host and port has its own file, so
shop.example.comneeds a separate one. - It must be UTF-8 plain text. Google reads the first 500 KiB and ignores anything after that.
- Rules are voluntary. Reputable crawlers obey them; malicious bots do not, so robots.txt is not a security control.
- Google generally caches the file for up to 24 hours.
Syntax: groups, user-agents and rules
A robots.txt file is made of groups. Each group starts with one or more User-agent lines naming the crawlers it applies to, followed by Allow and Disallow rules. Paths start with a slash and are case-sensitive.
# Rules for every crawler without a more specific group
User-agent: *
Disallow: /search/
Disallow: /cart/
Allow: /search/help/
# Googlebot follows only this group, not the * group above
User-agent: Googlebot
Disallow: /search/
Disallow: /cart/
Disallow: /print/
Sitemap: https://www.example.com/sitemap.xml- A crawler follows only the most specific group that matches its name, so repeat any shared rules in that group.
- An empty
Disallow:line allows everything for that group. Sitemaplines sit outside groups and need a full URL; see the XML sitemap guide.- Google ignores
Crawl-delay, and it stopped supportingnoindexrules in robots.txt in 2019.
Wildcards and matching rules
RFC 9309 supports two special characters. * matches any sequence of characters, and $ marks the end of the URL. When several rules match a URL, the rule with the longest path wins. If an Allow and a Disallow rule are equally long, Google uses the less restrictive Allow.
| Rule | Blocks | Does not block |
|---|---|---|
| Disallow: /blog | /blog, /blog/, /blog-old/, /blogging.html | /Blog/ (different case) |
| Disallow: /blog/ | /blog/ and everything under it | /blog, /blog-old/ |
| Disallow: /*?sort= | Any URL containing ?sort= | URLs with &sort= after another parameter |
| Disallow: /*.pdf$ | URLs ending in .pdf | /guide.pdf?download=1 |
| Disallow: /*? | Every URL with a query string | URLs without a ? character |
Be careful with short rules. Disallow: /p blocks /products/, /pricing/ and /privacy/ as well.
robots.txt versus noindex
These two tools are often confused, and using the wrong one is a common cause of indexing problems.
| robots.txt Disallow | noindex (meta tag or X-Robots-Tag) | |
|---|---|---|
| Controls | Whether a crawler may fetch the URL | Whether the page may appear in search results |
| Page can be indexed? | Yes, as a bare URL if other pages link to it | No, once Google has crawled and seen the tag |
| Use it for | Saving crawl effort on endless filters, internal search, carts | Thank-you pages, thin archives, private but reachable pages |
<!-- In the page head -->
<meta name="robots" content="noindex">
# Or as an HTTP header, useful for PDFs and other files
X-Robots-Tag: noindexDo not block a page in robots.txt and add noindex at the same time. Google cannot crawl the page, so it never sees the tag. Also avoid blocking CSS and JavaScript files, which Google needs to render pages, as the JavaScript SEO guide explains.
Managing AI crawlers
Several AI companies publish user-agent tokens that respect robots.txt. Some collect training data, while others fetch pages for search features or when a user asks a question. Each company documents its own tokens, and they change, so check the official pages before relying on this list.
| Token | Operator | Purpose |
|---|---|---|
| GPTBot | OpenAI | Collecting content for model training |
| OAI-SearchBot | OpenAI | Showing sites in ChatGPT search results |
| ClaudeBot | Anthropic | Collecting content for model training |
| Google-Extended | Controls use of content for Gemini models; does not affect Google Search | |
| Applebot-Extended | Apple | Controls use of content for Apple's AI model training |
| PerplexityBot | Perplexity | Indexing pages for Perplexity answers |
| CCBot | Common Crawl | An open web crawl that many AI datasets use |
# Opt out of AI training while staying in AI-powered search
User-agent: GPTBot
Disallow: /
User-agent: ClaudeBot
Disallow: /
User-agent: Google-Extended
Disallow: /
User-agent: CCBot
Disallow: /Blocking Google-Extended does not remove pages from Google Search or its AI Overviews, which are governed by Googlebot and snippet controls. Decide per crawler based on your goals; the AI search optimisation guide discusses the trade-offs.
Testing robots.txt and handling errors
In Search Console, Settings, the robots.txt report shows the files Google found for your property, when they were last fetched and any parsing problems. The URL Inspection tool tells you whether a particular URL is blocked.
- 404 or other 4xx: Google assumes there are no restrictions and crawls everything.
- 5xx server error: Google treats the whole site as disallowed at first. If the error lasts more than 30 days, it falls back to the last cached copy or assumes no restrictions.
- Redirects: Google follows up to five redirect hops to find the file.
Robots.txt reviews are part of every site audit, and writing safe rules for large sites is practised in the technical SEO course from SkillNewton.
Practical exercise: write and test a robots.txt file
- Open the robots.txt of a site you manage and copy it into a text file.
- List the sections that waste crawling, such as internal search, carts or sort parameters, and the sections that must stay crawlable.
- Write rules for those sections using
*and$where needed, plus a Sitemap line. - For ten sample URLs, work out by hand which rule wins using the longest-match principle, then confirm with URL Inspection after publishing on a test copy.
- Decide whether to add groups for AI crawlers and note the reason for each choice in a comment.
Common mistakes
- Leaving
Disallow: /in place after moving a site from staging to live. - Blocking a page in robots.txt and expecting it to disappear from search results.
- Blocking CSS or JavaScript folders that Google needs to render pages.
- Writing paths with the wrong letter case and blocking nothing.
- Listing private folders in the public file instead of protecting them with a login.
Frequently asked questions
Does every website need a robots.txt file?
No. Without one, crawlers assume they may fetch everything. A file is useful when you need to limit crawling or point crawlers to your sitemap.
How quickly do changes take effect?
Google usually refreshes its cached copy within a day. You can ask for a recrawl of the file from the robots.txt report in Search Console.
Can I block a single crawler only?
Yes. Add a group with that crawler's user-agent token and a Disallow: / rule. Other crawlers keep following their own groups.
Do all bots obey robots.txt?
No. Following it is voluntary. Use server-side blocking, rate limits or a firewall for crawlers that ignore it.