How to Write a robots.txt
A robots.txt tells crawlers which paths not to fetch. It lives at the root of the domain, groups rules under one or more User-agent lines, and can point to your sitemap. The crucial limit: it controls crawling, not indexing. A blocked URL can still be listed in search results, because the crawler never sees the page to read a noindex instruction.
robots.txt Generator
Build a valid robots.txt, with or without the AI crawlers.
The file is simple and its semantics are widely misunderstood in two specific ways, both of which cause real damage. The first is believing that blocking a path removes it from search. The second is not knowing that naming a crawler detaches it from the wildcard rules entirely.
Get those two right and the rest is a handful of lines.
Step by step
-
Put the file at the domain root
Exactly at /robots.txt. Anywhere else is ignored, and every subdomain needs its own — a file on the apex does not cover blog.example.com. It is served over both http and https and each is checked separately.
-
Understand how groups work
A group is one or more User-agent lines followed by rules. A crawler obeys only the single most specific group that matches it, so naming GPTBot means it ignores your wildcard group completely. Any group that names crawlers must carry its own full set of rules.
-
Keep each group contiguous
No blank line between a User-agent line and its rules. The original specification treats a blank line as a record separator, so a gap can orphan the rules from their group in stricter parsers. Comments are safe; blank lines separate groups.
-
Write the disallow rules
Paths are prefixes, so Disallow: /admin blocks /admin and everything under it. An empty Disallow means nothing is blocked. Google and Bing also support * for any sequence and $ for the end of a URL, which is how you exclude patterns such as /*?q=.
-
Add the sitemap line
Sitemap: followed by the absolute URL. It sits outside any group and applies to the whole file. It is the simplest way to make sure crawlers find your sitemap without submitting it anywhere.
-
Decide about AI crawlers deliberately
Training crawlers such as GPTBot, CCBot and Google-Extended are a different question from answer engines such as OAI-SearchBot and PerplexityBot, which fetch pages to cite them and can send traffic. Blocking everything gives up the second to prevent the first.
-
Do not use it to hide anything
The file is public and its whole purpose is to name paths. Listing /admin-secret tells every visitor exactly where it is. Protect sensitive paths with authentication; robots.txt is a request, not a control.
Example
Two groups. The named group repeats the rules because it would otherwise inherit nothing.
robots.txt
User-agent: GPTBot
User-agent: CCBot
Disallow: /
User-agent: *
Allow: /
Disallow: /admin
Disallow: /*?q=
Sitemap: https://example.com/sitemap.xml
What it does
GPTBot and CCBot: blocked entirely.
They read only their own group.
Everyone else: allowed, except
/admin and any URL with a q
parameter.
Sitemap applies to all crawlers.
Frequently asked questions
Will Disallow remove a page from Google?
Why must named groups repeat the rules?
Does Google support Crawl-delay?
Should I block my search results pages?
What happens if there is no robots.txt?
Tools used in this guide
All tools →- robots.txt Generator Build a valid robots.txt, with or without the AI crawlers. In your browser
- Meta Tag Generator Generate the meta, Open Graph and Twitter tags for a page. In your browser
- URL Redirect Checker Follow a redirect chain and see every hop. Server-side
- HTTP Header Checker Inspect the response headers and status a URL returns. Server-side
- URL Parser Split a URL into its scheme, host, path, query and fragment. In your browser
Related guides
All guides →Last reviewed .