Skip to main content
Best Web Developer — web design, development and digital growth agency
Language and currency EN $ USD

Language

  • More languages coming soon

Currency

Prices on this site are shown in the currency you choose.

Documentation

robots.txt: how it works and how to get it right

Groups, precedence, wildcards, status codes, AI crawlers and the mistakes that quietly block important pages.

The short version

robots.txt is a plain text file at the root of a host that tells crawlers which URLs they may request. It controls crawling, not indexing, and it is not access control. Use it to keep crawlers out of areas that waste crawl effort, such as internal search results or endless filter combinations. Do not use it to hide pages from search results or to protect private content.

Where the file lives

The file must be at /robots.txt on each host and protocol it applies to. https://example.com/robots.txt covers only https://example.com. The www subdomain, other subdomains and the http version each need their own file, or a redirect to one. It must be served as plain text, encoded as UTF-8, and Google reads only the first 500 KiB.

Syntax

The file is made of groups. Each group starts with one or more User-agent lines naming crawlers, followed by Allow and Disallow rules. Sitemap lines can appear anywhere and apply to the whole file. Everything after # is a comment.

# Default rules for every crawler without its own group
User-agent: *
Disallow: /search
Disallow: /cart/
Allow: /cart/help/

# Bing gets the same rules plus one more
User-agent: Bingbot
Disallow: /search
Disallow: /cart/
Allow: /cart/help/
Disallow: /beta/

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

Field names are not case-sensitive. Paths are case-sensitive and match from the start of the URL path, including the query string. Each rule should start with / or *.

Which group a crawler follows

A crawler looks for groups whose User-agent matches its product token, such as Googlebot or GPTBot, ignoring case. If it finds any, it combines their rules and ignores everything else, including the * group. Only a crawler with no group of its own falls back to *. That is why the Bingbot group above repeats the general rules: without them Bingbot would crawl /search.

Google adds one convenience: its specialised crawlers, such as Googlebot-Image and Googlebot-News, follow the Googlebot group when no group names them.

Which rule wins

Inside the chosen group, the rule with the longest matching path wins, whatever order the rules are in. If an Allow and a Disallow rule are equally long, Allow wins. Two wildcards are supported:

  • * matches any run of characters, including none.
  • $ at the end of a rule means the URL must end there.
User-agent: *
Disallow: /*.pdf$      # blocks /guide.pdf, not /guide.pdf?v=2
Disallow: /*?sessionid= # blocks any URL with that parameter
Allow: /downloads/brochure.pdf$

The Allow rule is longer than /*.pdf$, so the brochure stays crawlable while other PDFs are blocked.

Status codes

  • 200: the rules are used.
  • 3xx: Google follows up to five redirects and uses the result.
  • 4xx, including 404: treated as if there were no robots.txt, so everything may be crawled.
  • 5xx or no response: Google stops crawling the site for a while, as if everything were disallowed, and uses its last cached copy if it has one. A long-running server error on robots.txt can therefore halt crawling of the whole site.

Google caches robots.txt for up to 24 hours, so changes are not instant.

AI crawlers

AI companies publish separate user agents for different purposes, and each needs its own rule. Training crawlers include GPTBot, ClaudeBot and CCBot. Search and answer crawlers include OAI-SearchBot, Claude-SearchBot and PerplexityBot. User-triggered agents such as ChatGPT-User fetch a page when someone asks about it. Google-Extended and Applebot-Extended are tokens only: they never fetch anything, and you use them to control whether content Google or Apple already crawls may be used for AI models, without affecting search.

User-agent: GPTBot
User-agent: ClaudeBot
User-agent: Google-Extended
Disallow: /

Decide crawler by crawler and record why. Blocking every AI agent also removes you from AI search features that could send visitors.

Common mistakes

  • Blocking CSS, JavaScript or images. Search engines render pages. If they cannot load your assets, they may see a broken or empty page.
  • Using robots.txt to remove pages from search. A blocked page can still be indexed from links, and crawlers cannot see a noindex tag on a page they may not fetch. Allow crawling and use noindex instead.
  • Noindex: in robots.txt. Google stopped supporting it in 2019.
  • Leftover Disallow: / from a staging site that went live.
  • Relying on Crawl-delay. Google ignores it. Bing still reads it.
  • Listing secret paths. The file is public, so it advertises what it lists. Protect private areas with authentication.

Verifying a change

  1. Draft the new file and test it against a list of important URLs, including page templates and the assets they load, with the robots.txt Tester.
  2. Check AI and search crawlers separately with the AI Bot Access Tester.
  3. Publish the file, fetch /robots.txt in a browser and confirm it returns 200 with the new content.
  4. In Google Search Console, open the robots.txt report to see the version Google fetched, and request a recrawl if it is urgent.

Questions

Common questions

The things clients actually want to know — costs, timelines, ownership and what happens after launch.

No. It only stops crawling. To remove a page from results, allow crawling and add a noindex robots meta tag or X-Robots-Tag header, or delete the page.

Not for Google or other RFC 9309 crawlers. The longest matching rule wins, and Allow wins a tie.

No. Without one, crawlers may fetch everything. A file is useful when you want to keep crawlers out of specific areas or to list your sitemap.

Google usually caches robots.txt for up to 24 hours. You can ask for a recrawl from the robots.txt report in Search Console.

They cannot. Each host serves its own file at its own /robots.txt.

Last reviewed: by the Best Web Developer engineering team.

Free strategy session

Let’s build something worth finding.

Tell us where you want the business to be in twelve months. We will come back with a costed plan, a realistic timeline, and the numbers we expect to move — no obligation, no jargon.

  • 30-minute call, no pitch deck
  • Fixed-price proposal in 48 hours
  • You own everything we build

Talk to a developer

Not a sales team

Response time
Within 1 business hour
Where we work
UK, USA & the Gulf
Contracts
No lock-in, monthly rolling
Working since
2023
infobestwebdeveloper.org

Free strategy session

Let’s build something worth finding.

Tell us where you want the business to be in twelve months. We will come back with a costed plan, a realistic timeline, and the numbers we expect to move — no obligation, no jargon.

  • 30-minute call, no pitch deck
  • Fixed-price proposal in 48 hours
  • You own everything we build

Talk to a developer

Not a sales team

Response time
Within 1 business hour
Where we work
UK, USA & the Gulf
Contracts
No lock-in, monthly rolling
Working since
2023
infobestwebdeveloper.org
Free consultation