How to Write a Robots.txt File (and What It Can't Do)

Learn robots.txt syntax, how user-agent groups and Allow and Disallow rules are matched, how to handle AI crawlers, and why robots.txt does not hide pages.

Updated September 29, 2026 5 min read

Use the free Robots.txt GeneratorCreate robots.txt with bot rules and sitemap links

Every website gets visits from automated crawlers: search engines building their index, SEO tools measuring backlinks, and a growing number of bots collecting text for AI models. The small plain-text file at /robots.txt is how you tell them which parts of your site they are welcome to crawl. One wrong line in it can quietly remove an entire site from search results, so it deserves more care than its size suggests.

This guide explains the robots.txt format, how crawlers decide which rule applies, how to write rules for specific bots including AI crawlers, and the important limits of what the file can do. It also shows how to generate a correct file without memorising the syntax.

How robots.txt works

A robots.txt file lives at the root of a host: https://www.example.com/robots.txt. It applies only to that exact protocol and host, so blog.example.com needs its own file. Crawlers that follow the Robots Exclusion Protocol fetch it before crawling and obey its rules.

The file is made of groups. Each group starts with one or more User-agent lines naming the crawler, followed by rules:

User-agent: *
Disallow: /admin/
Disallow: /cart/
Allow: /admin/help/

User-agent: GPTBot
Disallow: /

Sitemap: https://www.example.com/sitemap.xml
  • User-agent: * applies to every crawler that does not have a more specific group.
  • Disallow: /path/ asks crawlers not to fetch URLs starting with that path.
  • Allow: creates an exception inside a disallowed area.
  • Disallow: with nothing after it means "nothing is disallowed".
  • Sitemap: gives the full URL of an XML sitemap and can appear anywhere.

How the right rule is chosen

A crawler follows only one group: the most specific one matching its name. If you add a group for Googlebot, Googlebot ignores the * group completely, so any general rules must be repeated there. Within a group, Google uses the most specific (longest) matching path, and when an Allow and a Disallow match equally, the less restrictive Allow wins. Google also supports * as a wildcard inside paths and $ to mark the end of a URL, for example Disallow: /*.pdf$.

Paths are case-sensitive: /Admin/ and /admin/ are different.

What robots.txt cannot do

This is the part most often misunderstood.

  • It does not keep pages out of search results. A disallowed URL can still be indexed without its content if other sites link to it. To keep a page out of results, allow crawling and add a noindex robots meta tag, which you can create with the meta tag generator. A crawler that is blocked from the page can never see that tag.
  • It is not security. The file is public, and badly behaved bots ignore it. Listing /secret-reports/ in robots.txt effectively advertises it. Protect private areas with authentication.
  • It is a request, not enforcement. Major search engines and many AI companies say they honour it, but compliance is voluntary. For hard blocking, use server rules or a firewall.

Generate a robots.txt file

The Robots.txt Generator builds a valid file from a few choices.

  1. Open the Robots.txt Generator.
  2. Under Default rule for all robots, choose Allow all or Disallow all. Most public sites should allow all.
  3. Optionally set a Crawl-delay in seconds. Google ignores this directive, though some other crawlers respect it.
  4. In Disallowed paths, type a path such as /private/ and click Add. Remove any path with its bin icon. Use Allowed exceptions (one per line, optional) for paths that should stay crawlable inside a blocked folder.
  5. Under Rules for specific bots, set each crawler to Same as default, Allow or Block. The list covers search engines (Google, Google Images, Bing, Yahoo, DuckDuckGo, Baidu, Yandex), AI crawlers (OpenAI GPTBot, ChatGPT browsing, Google AI training, Anthropic ClaudeBot, Perplexity, Common Crawl, ByteDance) and SEO tools (Ahrefs, Semrush, Majestic). To block a crawler that isn't listed, type its user-agent name and click Block.
  6. Add one or more Sitemap URL(s). They must be absolute URLs starting with https:// or http://.
  7. Copy or download the finished robots.txt file, and upload it to your site root. Start over resets every option.

Other ways to create and check the file

Your CMS or SEO plugin

WordPress generates a virtual robots.txt, and SEO plugins let you edit it from the dashboard. Shopify and other hosted platforms provide their own templates. Use those editors when they exist, because a physical file uploaded over FTP may be ignored or overwritten.

Search engine tools

Google Search Console has a robots.txt report that shows which version Google fetched and any parsing errors. Bing Webmaster Tools offers similar checks. These show what the search engine actually sees, which is more reliable than any local test.

Testing specific URLs

To check whether a particular URL is blocked by a set of rules before you publish them, use the robots.txt tester.

Tips and pitfalls

Don't block CSS and JavaScript

Search engines render pages much like a browser. Blocking /assets/ or /wp-includes/ can stop them seeing your layout and content properly.

Watch out when launching from staging

Staging sites often use Disallow: / to stay out of search. Copying that file to production is one of the most common causes of a site vanishing from results. Check robots.txt as part of every launch.

Blocking AI crawlers is a business decision

Blocking training crawlers such as GPTBot, Google-Extended or CCBot may keep your content out of some future training data, but it does not remove content already collected, and it may also affect whether your pages are cited in AI-powered answers. Google-Extended is a control token for Google's AI uses and does not affect Googlebot or normal search. Check each company's current documentation, since crawler names and behaviours change.

Identify unknown bots first

If you see an unfamiliar crawler in your logs, decode its user-agent string with a user agent parser before deciding whether to block it.

Keep the sitemap in sync

Listing your sitemap in robots.txt helps crawlers find it. The sitemap generator can create one if you don't have it yet.

Frequently asked questions

Where does robots.txt go?

In the root directory of your domain, so it loads at https://yourdomain.com/robots.txt. Files in subfolders are ignored.

Does robots.txt remove pages from Google?

No. It controls crawling, not indexing. Use a noindex meta tag on a crawlable page, or remove the page, to take it out of search results.

What happens if I don't have a robots.txt file?

Crawlers treat a missing file as permission to crawl everything. That is fine for many small sites, although adding a sitemap line is still useful.

Can I block a single file type?

For crawlers that support wildcards, such as Googlebot, a rule like Disallow: /*.pdf$ blocks URLs ending in .pdf. Not every crawler supports these patterns.

Is crawl-delay supported by Google?

No. Google ignores crawl-delay. Some other search engines and crawlers respect it, so it can still be useful for them.

Try it now: Robots.txt Generator

Loading tool…