SEO Tools

robots.txt Explained: Rules, Syntax and Common Mistakes

A plain-English robots.txt guide: user-agent rules, allow and disallow syntax, crawl-delay, sitemap links, and the blocking mistakes that hurt SEO.

4 min read·Updated 2026-04-14

robots.txt is a small plain-text file at the root of your domain that tells automated crawlers which URLs they may request. It is the first file many bots read and the most misunderstood file in SEO. This guide explains every directive that matters, shows correct grouping syntax, and walks through the mistakes that quietly drop entire sections of a site out of the index.

What robots.txt is — and what it is not

robots.txt is a crawl instruction, not an access control system. It lives at example.com/robots.txt, is fully public, and is honoured only by well-behaved bots. Scrapers that ignore it will fetch whatever they want. Its real job is politeness and crawl budget: keep robots away from filtered search pages, admin panels and infinite calendar loops so they spend their requests on content you actually want indexed.

Crucially, blocking a URL here does not remove it from the index. If other pages link to that URL, Google can still list it with a snippet built from those links. Genuine removal requires the meta robots noindex tag — a completely different mechanism.

File location and the directives that matter

The file must sit at the root of the host you want to control, encoded as UTF-8, with one directive per line. Blank lines separate rule blocks and the hash character begins a comment. These five directives cover almost every real use case:

DirectiveExampleMeaning
User-agent*Applies to every crawler that matches
Disallow/cart/Do not crawl URLs beginning with this path
Allow/cart/summary.htmlException — this URL may be crawled
Sitemap/sitemap.xmlAbsolute URL to your sitemap, repeated if needed
Crawl-delay10Seconds between requests; Bing honours it, Google ignores it

Grouping rules by user-agent

Rules only apply to the block they sit in. Googlebot and Bingbot are separate crawlers, so a block written for one does not affect the other. Follow this order when you build the file:

  1. Put a catch-all block with User-agent: * and your site-wide rules first.
  2. Add specific blocks for heavy crawlers such as GPTBot or SemrushBot when you need different treatment.
  3. Close each block with a blank line before the next User-agent line appears.
  4. Repeat the Sitemap line inside every block so each bot sees it.

When a URL matches both an Allow and a Disallow rule for the same agent, the more specific path wins — in Google's implementation, the longest matching rule decides, and Allow wins on equal length.

The mistakes that cost traffic

  • Blocking CSS and JavaScript. If Google cannot fetch your stylesheet or render scripts, the page is indexed as bare text and rankings suffer.
  • Disallowing a folder then linking to it. Blocked pages with internal links still get indexed without content, producing useless snippets.
  • Trailing slash errors. Disallow: /blog blocks /blog and every page under it, which is rarely what you meant.
  • Using robots.txt instead of noindex. Blocking a private page keeps it out of crawl, but not out of the index.
  • Forgetting the file on a new subdomain. Staging.example.com with no robots.txt gets indexed in days.

Pair it with a sitemap and clean canonicals

A robots.txt file works best as part of a trio: point every block at your XML sitemap, keep the sitemap free of redirected or canonicalised URLs, and make sure the pages you allow are the pages you want to rank. Build the file with the robots.txt Generator, then generate a matching XML Sitemap and check each canonical URL with the Canonical Tag Builder so the three files agree with one another.

Verify before you publish

After uploading, reload the file in a private window and confirm the status is 200 rather than 404 — a missing file means everything is crawlable, which is safe but not always intended. Then test one allowed URL and one blocked URL in your search console's inspection tool. The report tells you explicitly whether the robots.txt directive is the reason a page cannot be indexed.

Frequently asked questions

How often does Google crawl robots.txt? Roughly daily for most sites, and more often for sites that publish frequently. Changes can take up to 24 hours to be respected, so do not expect an immediate lift after editing.

Does robots.txt stop AI crawlers? Only the ones that follow it. OpenAI, Anthropic and Google publish crawlers that honour robots.txt, but nothing prevents a non-compliant scraper. Server-level authentication is the only true block.

Can robots.txt have comments? Yes. Everything after a hash on a line is ignored by crawlers, which makes it a good place to date your edits and note why a rule exists so the next person does not delete it.

Tools used in this guide

Related guides