Home / Blog / Indexing and Crawling / How do you write a robots.txt file?
Answers

How do you write a robots.txt file?

27 November 2026 · By John Carlsson
Write a robots.txt file as plain text saved at the root of your host, such as https://example.com/robots.txt. Group rules under a User-agent line, then add Disallow and Allow lines with URL paths, and optionally a Sitemap line with a full URL. Google follows the most specific matching rule. robots.txt controls crawling, not indexing, and is not a security measure.

What a robots.txt file does

A robots.txt file tells crawlers which URLs on a site they are allowed to request. It follows the Robots Exclusion Protocol, which became an internet standard as RFC 9309 in September 2022. Well behaved crawlers, including Googlebot, check the file before crawling and follow its rules.

Two limits are worth knowing from the start. First, robots.txt controls crawling, not indexing: Google explains that a disallowed URL can still be indexed if it is linked from elsewhere. Second, it is not access control. RFC 9309 states that the rules are not a form of access authorisation, and the file is public, so never use it to hide private content.

Where the file goes

The file must be called `robots.txt` and sit in the top level directory of the host, for example `https://www.example.com/robots.txt`. Rules only apply to the exact protocol, host and port where the file is served, so `https://shop.example.com` needs its own file. Crawlers do not look for robots.txt files in subdirectories.

Save it as plain UTF-8 text. Google processes up to 500 KiB of the file and ignores anything after that.

The rules

Google supports four fields:

Field names are not case sensitive, but paths are. Each path should start with `/`. Two wildcards are supported: `*` matches any sequence of characters and `$` marks the end of a URL.

How Google decides which rule applies

A crawler follows only one group, the one whose user agent most specifically matches its name. Within that group, Google applies the most specific matching rule, measured by the length of the path. If an allow and a disallow rule are equally specific, Google uses the less restrictive one, which is the allow rule.

Examples

A typical small site that keeps crawlers out of an admin area and a search results path:

``` User-agent: * Disallow: /admin/ Disallow: /search Allow: /admin/help/

Sitemap: https://www.example.com/sitemap.xml ```

Blocking one file type for Googlebot only:

``` User-agent: Googlebot Disallow: /*.pdf$ ```

Blocking the whole site for every crawler, which is useful on a staging copy but disastrous on a live site:

``` User-agent: * Disallow: / ```

How the server response matters

Google treats the status code of robots.txt as part of the instruction:

Google normally caches the file for up to 24 hours, so changes are not picked up instantly.

Common mistakes

  1. Leaving `Disallow: /` in place after launching a site that was built on a staging server.
  2. Blocking CSS or JavaScript files that pages need to render.
  3. Using robots.txt to remove pages from search instead of noindex.
  4. Forgetting that each subdomain needs its own file.
  5. Relying on unsupported fields such as crawl-delay for Googlebot.

Check your robots.txt

Our LLMs.txt Auditor is built for llms.txt files, but it checks your robots.txt alongside llms.txt and llms-full.txt, and flags a noindex header that conflicts with the llms.txt file. Use it as a check that the two files work together, not as a full robots.txt validator.

Sources

Frequently asked questions

Does a robots.txt file stop a page appearing in Google?

Not reliably. robots.txt controls crawling, not indexing. Google explains that a URL blocked in robots.txt can still be indexed, without a description, if other pages link to it. To keep a page out of search results, allow it to be crawled and use a noindex robots meta tag or header, or protect it with a password.

Does Google support Crawl-delay in robots.txt?

No. Google supports only the user-agent, allow, disallow and sitemap fields, and ignores others such as crawl-delay. Some other crawlers, including Anthropic's, do honour crawl-delay. Adding crawl-delay will not slow Googlebot, so if you need it for other crawlers, place it only in their user agent groups and do not expect any effect on Google.

💬 Got a problem?

aiwebpageseo.com is a data-driven SEO and AEO platform providing a free suite of technical website tools.