Robots.txt is a 10-line file that can take a whole site out of search results — with one misplaced slash. This guide covers the syntax that actually matters, the limits search engines enforce, and how to test a file safely before it goes live.

Syntax: only three directives do real work

User-agent: *
Disallow: /admin/
Allow: /admin/public/
Sitemap: https://example.com/sitemap.xml
  • User-agent starts a group of rules. * means everyone; a specific bot (Googlebot) gets its own group and ignores the * one.
  • Disallow blocks path prefixes. An empty Disallow: value means “allow everything” — it’s the canonical way to say “you may crawl me”.
  • Allow carves exceptions out of a Disallow. When a path matches both, the longest (more specific) rule wins — not the order in the file.
  • Sitemap: the only way to tell crawlers where the sitemap is without Search Console.

Wildcards work in most modern engines: * is any character run, $ anchors the end — Disallow: /*.pdf$ blocks all PDFs.

Hard limits and quirks

  • File size: 500 KiB (Google). Rules beyond the limit are ignored — a bloated file silently stops working.
  • Location and case matter: it must be https://example.com/robots.txt — lowercase, at the root of each hostname. /Robots.TXT is a 404, and a 404 means “crawl everything”.
  • Crawl-delay is ignored by Google (Bing and Yandex respect it). If you need to throttle Google, that’s server configuration, not robots.txt.
  • The file applies to the hostname only: rules on example.com do nothing for www.example.com or a subdomain — each needs its own file.
  • Groups don’t merge: a bot uses the single most specific group it matches; you can’t define Googlebot twice and expect both blocks to apply.

The crawling vs indexing trap

This is the mistake that costs people data: robots.txt controls crawling, not indexing. If you block a URL in robots.txt, Google can’t fetch it — and therefore can’t read a noindex on the page. Worse, the URL may still appear in results (without a description) because someone linked to it. The correct split:

  • Want it out of the index entirely → noindex meta/X-Robots-Tag, page must stay crawlable (don’t block it in robots.txt).
  • Want to save crawl budget on junk (facets, search results, logs) → robots.txt Disallow, and accept the URL may still show up as a bare link.
  • Doing both on the same URL = the worst option: you neither save the budget (it was already linked) nor reliably remove it from the index.

How to validate before it hurts

A typo in Disallow can de-index your shop in days. Check the file:

curl -s https://example.com/robots.txt

…and then ask what a crawler would actually do: is /admin/ really blocked, is the sitemap line reachable, does the file return 200 (not a soft 404 HTML page)? For a batch of domains, a bulk robots.txt checker reports the status, redirects, size, number of sitemap directives and whether the file blocks all robots — across your whole domain list in one run, which is how you catch the one staging environment someone forgot to unblock. For a single domain, the instant robots.txt check shows the same without a terminal.

After the file, check the pages themselves: noindex metas and canonicals — an indexation checker reads what search engines will read, per page. And if your file declares sitemaps, a sitemap checker verifies they parse and how fresh their lastmod dates are.

Common mistakes

  • Blocking CSS/JS directories (a legacy of old guides): Google can’t render the page properly and ranks it worse. Modern rule: don’t block assets.
  • Disallow with a typo in the environment — Disallow: / committed to production from staging. This one empties a site from the index; check every deploy.
  • Expecting privacy from robots.txt — it’s a polite request, publicly readable at /robots.txt. Secrets don’t belong there at all; the file only advertises them.
  • Testing only the homepage host while the site also lives on www. or a staging subdomain — each hostname needs its own file and its own check.

Check all your robots.txt files at once: run a bulk robots.txt check over your domain list — status, redirects, sitemaps and “blocks everything” verdicts in one report.