Robots.txt is a plain text file at the root of your site that tells crawlers which URLs they may request. For SEO, it does two useful jobs: it keeps search engines from wasting time on areas that don’t need crawling, and it points them to your sitemap. It also causes some of the most damaging mistakes in SEO, because a single misplaced line can stop search engines crawling your whole site, and because many people expect it to do something it doesn’t: keep pages out of search results.
This guide covers robots.txt for SEO the way Google actually reads it: where the file lives, how rules are matched and which one wins, copyable examples for common setups, how to handle AI crawlers, the mistakes to avoid, and how to test your file.
The short version
- Robots.txt controls crawling, not indexing. Blocked URLs can still appear in results if linked from elsewhere.
- One file per host, at
/robots.txt, returning a 200 status. - The most specific rule wins; on a tie between allow and disallow, allow wins (for Google).
- Wildcards:
*matches any characters,$marks the end of the URL. Paths are case-sensitive. - Google ignores crawl-delay and noindex in robots.txt.
- Never block CSS and JavaScript that pages need to render.
- Decide on AI crawlers one by one; search crawlers and training crawlers do different jobs.
- Test before you publish changes.
How robots.txt works
A crawler that respects the protocol fetches /robots.txt before crawling a host and follows the rules that apply to it. Google’s introduction to robots.txt describes it as a way to manage crawler traffic, mainly to avoid overloading your site with requests, and is clear that it isn’t a mechanism for keeping a page out of Google. The protocol itself is now an internet standard, RFC 9309, which Google helped write.
A basic file looks like this:
User-agent: *
Disallow: /search/
Disallow: /cart/
Allow: /
Sitemap: https://www.example.com/sitemap.xml
The rules Google follows
Google’s robots.txt specification sets out how its crawlers interpret the file. The points that matter most:
Location and scope. The file must be in the top-level directory of the host. It applies only to that protocol, host and port: https://shop.example.com needs its own file, separate from https://www.example.com.
Size and caching. Google reads up to 500 KiB and ignores the rest. It generally caches the file for up to 24 hours, so changes aren’t instant.
Status codes.
| Response | What Google does |
|---|---|
| 200 | Reads and follows the file |
| Redirect | Follows up to five hops; beyond that treats it as not found |
| 4xx (except 429) | Treats it as if no robots.txt exists: no restrictions |
| 5xx or network error | Stops crawling for 12 hours, then uses the last cached version for up to 30 days |
A missing file means “crawl everything”, which is fine. A server error on robots.txt can pause crawling of your whole site, which isn’t.
Supported fields. User-agent, Disallow, Allow and Sitemap. Google ignores everything else, including Crawl-delay and Noindex.
Which group applies. A crawler follows only the single group with the most specific matching user-agent. If you have a User-agent: Googlebot group, Googlebot ignores the User-agent: * group entirely, so rules you put in * don’t apply to it.
Which rule wins. Within a group, the rule with the longest matching path wins. If an allow and a disallow match with equal length, Google uses the less restrictive one: allow.
Wildcards and case. * matches any sequence of characters; $ matches the end of the URL. Paths are case-sensitive: Disallow: /Private/ doesn’t block /private/.
Worked examples of rule precedence
| Rules | URL | Result |
|---|---|---|
Disallow: /shop/ and Allow: /shop/sale/ |
/shop/sale/boots | Allowed (longer match) |
Disallow: /shop/ and Allow: /shop/sale/ |
/shop/new/boots | Blocked |
Disallow: /*.pdf$ |
/guides/boiler.pdf | Blocked |
Disallow: /*.pdf$ |
/guides/boiler.pdf?v=2 | Allowed (doesn’t end in .pdf) |
Disallow: /*?sort= |
/shoes/?sort=price | Blocked |
Allow: /page and Disallow: /page |
/page | Allowed (tie goes to allow) |
Copyable robots.txt examples
A typical small business site
Most small sites need very little:
User-agent: *
Disallow:
Sitemap: https://www.example.com/sitemap.xml
An empty Disallow allows everything. If your platform creates admin or search URLs, add those.
An online shop
Keep crawlers out of cart, checkout, account and internal search pages, and away from sort and filter parameters that create endless combinations, while leaving categories and products open:
User-agent: *
Disallow: /cart/
Disallow: /checkout/
Disallow: /account/
Disallow: /search
Disallow: /*?sort=
Disallow: /*?*filter=
Sitemap: https://www.example.com/sitemap.xml
Adjust the patterns to your platform’s real URLs, and leave crawlable any filter pages you want indexed. Our e-commerce SEO guide covers which filtered pages deserve indexing.
A WordPress site
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://www.example.com/sitemap_index.xml
The Allow line keeps a file that some themes and plugins need for front-end features crawlable.
Robots.txt and AI crawlers
AI companies run their own crawlers, and you can address each in robots.txt. They don’t all do the same job:
# Allow ChatGPT search, opt out of OpenAI model training
User-agent: OAI-SearchBot
Allow: /
User-agent: GPTBot
Disallow: /
# Opt out of some Google AI training and grounding, without affecting Search
User-agent: Google-Extended
Disallow: /
OpenAI says sites that block OAI-SearchBot won’t appear in ChatGPT search answers, while GPTBot is used for training. Google-Extended controls use of your content for some of Google’s AI systems but not Search or AI Overviews, which use Googlebot. Our AI crawlers guide covers the main bots and what blocking each one does.
You can see which AI crawlers your current file allows or blocks with our free AI Crawler Checker, which reads your robots.txt and applies Google’s matching rules.
Robots.txt mistakes that hurt SEO
| Mistake | What happens | Fix |
|---|---|---|
Disallow: / left over from a staging site |
Nothing gets crawled | Remove it at launch; protect staging with a password instead |
| Blocking CSS or JavaScript files | Pages can’t render properly for search engines | Allow the resources pages need |
| Using robots.txt to hide a page from results | Page can still be indexed without content | Allow crawling and use noindex |
| Blocking a page that has a noindex tag | Crawlers can’t see the noindex, so the page may stay indexed | Allow crawling until it drops out |
| Blocking pages you’ve canonicalized | Crawlers can’t see the canonical tag | Let them be crawled |
Rules in User-agent: * meant for Googlebot, with a separate Googlebot group |
Googlebot ignores the * group |
Repeat needed rules in the Googlebot group |
| Wrong case in paths | Rules don’t match | Match the URL’s exact case |
| robots.txt returning 5xx | Crawling pauses | Make sure it returns 200 reliably |
| Listing private URLs | Anyone can read robots.txt, so it advertises them | Protect private areas properly |
How to test your robots.txt
- Open
/robots.txtin a browser and confirm it loads with the content you expect. - Check the robots.txt report in Search Console, which shows the files Google found for your property, when they were last fetched and any parsing problems.
- Inspect important URLs with the URL Inspection tool and check “Crawl allowed”.
- Test specific URLs against your rules before deploying changes; our AI Crawler Checker tests the main AI user-agents, and SEO crawlers can simulate others.
- Watch crawl stats after changes, and check that important pages are still being crawled.
How to change robots.txt safely
Because one line can block a whole site, treat robots.txt changes like code changes:
- Write down why you’re changing it and which URLs should be affected.
- Test the new rules against a list of important URLs (homepage, key categories, top products, key guides) and a few you mean to block.
- Check the user-agent groups: if you add a group for one crawler, it will ignore the
*group, so copy across any rules it still needs. - Deploy and fetch the live file to confirm the server serves exactly what you wrote, with a 200 status.
- Remember the cache: Google can take up to a day to pick up the change.
- Watch Search Console over the following weeks for crawl and indexing changes on important pages.
Robots.txt on large sites
On big sites, robots.txt becomes a crawl management tool. Sites with millions of URLs often use it to keep crawlers away from infinite spaces: calendars that go on forever, faceted filters with endless combinations, session URLs and internal search results. Freeing crawlers from those areas helps them spend time on pages that matter. On a typical small business site, though, there’s rarely a crawl problem to solve, and the safest robots.txt is a short one.
When to use robots.txt, and when not to
| Goal | Use |
|---|---|
| Stop crawlers wasting time on internal search, carts or endless filters | robots.txt |
| Point crawlers to your sitemap | robots.txt |
| Keep a page out of search results | noindex (and allow crawling) |
| Consolidate duplicate URLs | Canonical tags or redirects |
| Protect private content | Password protection or authentication |
| Reduce load from a specific bot | robots.txt for that user-agent, or server-side rate limiting |
Get your robots.txt right
Robots.txt is short, but it sits at the front door of your site. Review it whenever you launch, migrate or change platforms, and test every change. Our technical SEO guide covers crawling and indexing more broadly, and our technical SEO team can review your robots.txt alongside sitemaps, canonicals and crawl data.
