How to Write a robots.txt File: Disallow, Allow, Bot Groups and noindex

Last updated: · 8 min read

robots.txt is a plain-text file in the root of a site that tells crawlers which URLs they may fetch. Its rules are standardised in RFC 9309, the Robots Exclusion Protocol. The file is a crawling directive and nothing more: it does not stop anyone from opening a page, and on its own it does not take a page out of search results. Sites that miss this distinction end up with supposedly private pages left open, or with pages they wanted removed still showing up in results. This guide covers the syntax, how a crawler picks its group and its rule, the Crawl-delay and Sitemap lines, and the mistakes that cause the most damage. The lines in the worked example are real output from the robots.txt Generator.

Formula

User-agent: <crawler name or *>
Disallow: <path>        (an empty value blocks nothing)
Allow: <path>

Sitemap: <absolute URL>

Group choice : a crawler follows the group that names it; if there is none, the * group
Rule choice  : the longest rule (most bytes) that matches the URL path applies
Tie          : if an Allow and a Disallow of equal length match, Allow is used
Characters   : * = any sequence of characters,  $ = end of the path,  # = comment
Location     : https://host/robots.txt (one file per protocol, subdomain and port)

The file is a list of groups. Each group opens with one or more User-agent lines, followed by the Allow and Disallow rules for those crawlers. Under RFC 9309 a crawler first looks for a group matching its own name, ignoring case, and falls back to the * group only when it finds none. A crawler with its own group does not read the * group; Google's documentation likewise says only one group is valid for a given crawler and the others are ignored. That is why the tool copies your general rules into every bot-specific group. When several rules match a URL, the longest one wins, and for rules of equal length the RFC says Allow should be used. Rules are compared as path prefixes: Disallow: /admin covers not only the /admin/ directory but also /administrator. The Sitemap line is not part of the core protocol; the RFC lets crawlers interpret such extra records, and Google supports this one. Crawl-delay is not defined in the RFC at all.

What the inputs mean

Default rule
Allow the whole site, or Block the whole site. The second writes Disallow: / into the * group and is meant for sites that are not ready to be crawled.
Paths to disallow
One path per line. A path must start with / or *; the * and $ characters may be used. Non-ASCII characters are converted to UTF-8 percent-encoding.
Paths to allow
Optional. Use it for sub-paths that should stay open inside a blocked directory; a longer Allow rule overrides a shorter Disallow rule.
Bot-specific blocks
One "BotName: /path" per line. "BotName: /" keeps that crawler away from the whole site. A name may contain only letters, digits, - and _; take the exact name from the crawler operator's own documentation.
Sitemap URL
Optional. It must be an absolute URL starting with http:// or https://, and it is written as a Sitemap line at the end of the file.
Crawl delay
A whole number of seconds from 0 to 3600. With 0, no Crawl-delay line is written. The line is not part of RFC 9309 and is not supported by Google.

Worked example: Admin and cart pages blocked, with rules for two specific bots

  1. Input: Default rule = Allow the whole site; Paths to disallow = /admin/ and /cart/; Paths to allow = /admin/help/; Bot-specific blocks = GPTBot: / and ExampleBot: /drafts/; Sitemap URL = https://www.example.com/sitemap.xml; Crawl delay = 0.
  2. The general group has four lines: User-agent: *, then Disallow: /admin/, Disallow: /cart/ and Allow: /admin/help/.
  3. Longest match: the URL /admin/help/faq matches both Disallow: /admin/ (7 characters) and Allow: /admin/help/ (12 characters). The longer Allow rule wins and the URL may be crawled, while /admin/users matches only the Disallow rule and stays blocked.
  4. GPTBot gets a group of its own: User-agent: GPTBot and Disallow: /. That crawler is asked to stay away from the entire site.
  5. The ExampleBot group reads User-agent: ExampleBot, then Disallow: /admin/, Disallow: /cart/, Disallow: /drafts/ and Allow: /admin/help/. You only typed /drafts/, yet the general rules are there too, and the tool's note explains why: A crawler with its own group follows only that group, so the general rules were copied into the bot groups as well.
  6. The last line of the file is Sitemap: https://www.example.com/sitemap.xml. Two more notes appear under the output. Upload the file as robots.txt to the root of your site (example: https://www.example.com/robots.txt). robots.txt only guides crawling, it does not block access; protect private pages with a password.
  7. Set the crawl delay to 10 and clear the bot field: the * group gains the line Crawl-delay: 10. Crawlers that recognise the line apply it; Google's documentation states plainly that the crawl-delay field is not supported.
  8. Switch the default rule to Block the whole site and enter /public/ as an allowed path: the output becomes Disallow: / and Allow: /public/, so only URLs under /public/ may be crawled.
  9. Non-ASCII paths and wildcards: the input /ürünler/taslak/ is written as Disallow: /%C3%BCr%C3%BCnler/taslak/, and /*.pdf$ is written as Disallow: /*.pdf$. The second rule covers every URL whose path ends in .pdf.
  10. Leave out the leading slash (admin/) and the tool refuses to build the file: Disallowed paths, line 1: a path must start with / or * (example: /admin/).

Result: The generated file has three groups: User-agent: * (two Disallow rules and one Allow), User-agent: GPTBot (Disallow: /) and User-agent: ExampleBot, which also carries the general rules. It ends with Sitemap: https://www.example.com/sitemap.xml.

🤖 robots.txt Generator

Free, no sign-up; your data stays in your browser.

Open the calculator →

How to read the result

Two things are easy to confuse with robots.txt: crawling and indexing. Google's documentation says robots.txt is not a mechanism for keeping a page out of Google; a disallowed URL can still be indexed, without its content being crawled, if other pages link to it. When a page must not appear in results, use noindex (a meta tag or an X-Robots-Tag response header) and do not block the page in robots.txt, because the crawler has to fetch the page to see that rule. For content that is really private, authentication is the only answer: the file is public, obeying it is the crawler's choice, and RFC 9309 states that these rules are not a form of access authorization. After publishing the file, open https://your-host/robots.txt in a browser and check that it returns status 200 and plain text. Google generally caches the file for up to 24 hours and stops reading after 500 kibibytes; if the file returns a 4xx status other than 429, Google behaves as if there were no restrictions. Under the RFC, a server error (5xx) means the crawler must assume the whole site is disallowed. Crawlers may interpret the syntax differently, so confirm important rules against the documentation and testing tools of the search engine you care about.

Common mistakes

  • Using Disallow to remove a page from search results. Crawling stops, but the URL can still be indexed through links. Removal needs noindex or password protection.
  • Putting both Disallow and noindex on the same page. The crawler cannot fetch the page, so it never sees the noindex rule.
  • Treating robots.txt as a privacy tool. The file is public, and a line such as /confidential-reports/ tells everyone that the directory exists.
  • Placing the file in a subdirectory, or assuming one file covers every subdomain. A robots.txt applies only to the protocol, host and port it is served from; blog.example.com needs its own file.
  • Expecting a crawler with its own group to obey the * group as well. Once you add a bot-specific group, the general rules have to be repeated inside it; the tool does this for you.
  • Shipping the staging site's Disallow: / to production. The whole site is closed to crawling; put robots.txt on your launch checklist.
  • Ignoring the trailing slash. Disallow: /admin also covers /administrator and /admin.html; write /admin/ if you mean the directory only.
  • Trying to slow Google down with Crawl-delay. Google does not support the field; the line matters only to crawlers that recognise it.

Frequently asked questions

Where does the robots.txt file go?

In the top-level directory of the site, with the name robots.txt in lower case: https://www.example.com/robots.txt. Crawlers do not read a file in a subdirectory such as /blog/robots.txt. The file must be plain text encoded as UTF-8.

Does Disallow remove a page from Google?

No. Disallow only stops crawling. Google's documentation notes that a disallowed URL may still be indexed if it is linked from other places. To keep a page out of results, leave it crawlable and use noindex, or protect it with a password.

Which rule wins when Allow and Disallow conflict?

The longest rule that matches the URL path. If two matching rules have the same length, RFC 9309 says the Allow rule should be used, and Google's documentation says it uses the least restrictive rule in a conflict.

Can I block AI crawlers with robots.txt?

You can write a group that names the crawler; in the tool, the line "GPTBot: /" produces a group with User-agent: GPTBot and Disallow: /. This is a request, not a technical barrier: whether the rule is honoured is up to the crawler's operator. Take the exact user-agent name from that operator's documentation.

Does Crawl-delay work for Google?

No. Google's documentation lists user-agent, allow, disallow and sitemap as the supported fields and says other fields such as crawl-delay are not supported. The line is not defined in RFC 9309 either; its effect is limited to crawlers that choose to recognise it.

What happens if a site has no robots.txt?

When Google receives a 4xx status for the file (other than 429), it treats the site as if no valid robots.txt existed and assumes there are no crawl restrictions. A missing file therefore does not stop a site from being crawled.

Do I have to list my sitemap in robots.txt?

No, it is optional. A Sitemap line must hold an absolute URL, does not belong to any group and may appear more than once. The tool writes it at the end of the file.

The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.

Sources

Choose your cookie preference to continue

Records the site needs to work (theme, language, favourites) stay in your browser.

This site is free and funded by ads.

With your consent, Google Analytics cookies measure visits and Google AdSense cookies are used to show ads; the data is processed on Google servers abroad.

If you reject, the site works just the same.

Cookie Policy · KVKK notice