Developer Tools

robots.txt explained: Allow, Disallow, wildcards and the mistakes that block your site

One small text file can tell search engines to crawl your whole site or none of it. This guide covers the four directives that matter, how crawlers pick between conflicting rules, why robots.txt is not a security tool, and the single-character slip that has taken sites out of search.

By the Toolcloak team9 October 20264 min read
In this article
  1. The shape of the file
  2. A complete example
  3. How crawlers choose between rules
  4. Wildcards and the end marker
  5. The mistakes that hurt most
  6. robots.txt against noindex
  7. Limits and details worth knowing
  8. Before you publish

Before a well-behaved crawler visits any page on your site, it first asks for one file: /robots.txt. The file lists which parts of the site it may crawl and which it should skip. It is simple, and that is the danger: a single wrong line can hide an entire website from search.

The shape of the file

The file is plain text, built from groups. Each group starts with the crawler it addresses, followed by the rules for it.

DirectiveMeaningExample
User-agentWhich crawler the group applies to. * means all.User-agent: Googlebot
DisallowA path the crawler should not fetchDisallow: /admin/
AllowA path that is allowed, used to carve out exceptionsAllow: /admin/help/
SitemapFull address of your XML sitemap, outside any groupSitemap: https://example.com/sitemap.xml

Paths are case-sensitive and start with a slash. /Admin/ and /admin/ are different.

Choose crawlers, add allow and disallow paths and your sitemap, then copy the finished file.Open Robots.txt Generator

A complete example

A typical small-site file, read line by line
  1. 1User-agent: *The rules below apply to every crawler that has no group of its own.
  2. 2Disallow: /admin/Do not crawl anything under /admin/.
  3. 3Disallow: /cart/Skip the shopping cart. It has no value in search.
  4. 4Allow: /admin/help/But the help pages inside /admin/ may be crawled.
  5. 5Sitemap: https://example.com/sitemap.xmlTell crawlers where the full list of pages is.

A crawler follows the most specific matching group. A named group such as Googlebot replaces the * group for that crawler. It does not add to it.

How crawlers choose between rules

Rules can overlap. Google and most major crawlers pick the longest matching path, because it is the most specific. If an Allow and a Disallow match with equal length, the less restrictive one, Allow, wins.

URLMatching rulesResult
/admin/loginDisallow: /admin/Blocked
/admin/help/faqDisallow: /admin/ and Allow: /admin/help/ (longer)Allowed
/cart/Disallow: /cart/Blocked
/blog/post-1No rule matchesAllowed (the default)

Anything not mentioned is allowed. You only list what you want kept out.

Wildcards and the end marker

Two special characters work in Google, Bing and most other major crawlers. Both can save you from writing hundreds of lines.

Pattern characters
* (star)Matches any run of characters. Disallow: /*?sort= blocks any URL containing ?sort=.
$ (end)Matches the end of the URL. Disallow: /*.pdf$ blocks addresses that end in .pdf.
Trailing slash/shop also matches /shop-sale. /shop/ matches only inside the folder.
No regexOnly these two characters are special. Full regular expressions do not work.

Test a new pattern before publishing. A star in the wrong place can match far more than you meant.

The mistakes that hurt most

One character apart
Blocks nothingDisallow:
  • An empty value means no restrictions
  • Every page may be crawled
  • Often used as an explicit 'allow all'
Blocks everythingDisallow: /
  • The slash means the whole site
  • Crawlers stop fetching all pages
  • Pages can drop out of search over time

This often happens when a staging file is copied to the live site. Check robots.txt after every launch.

  1. Staging rules on the live site. A leftover Disallow: / from a test server is the classic cause of a sudden loss of traffic.
  2. Blocking CSS and JavaScript. If a crawler cannot load your styles and scripts, it cannot see the page as visitors do.
  3. Using robots.txt to hide pages. The file is public. Listing /secret-offers/ advertises exactly where it is.
  4. Wrong location. It must be at the root of each host. blog.example.com needs its own file.
  5. Blocking a page you want removed. If a page is blocked, the crawler never sees a noindex tag on it.

robots.txt against noindex

These two tools solve different problems and are often confused.

GoalUseWhy
Save crawl effort on low-value URLsDisallow in robots.txtThe crawler does not fetch the page at all
Keep a page out of search resultsnoindex meta tag or headerThe crawler must be able to fetch the page to see it
Protect private dataPasswords or access rules on the serverrobots.txt is a request, not a lock
Remove an old page quicklyRemoval tool in Search Console, then noindex or 404Blocking alone can leave the address listed

Never combine Disallow and noindex on the same page and expect noindex to work.

Limits and details worth knowing

  • Size. Google reads about the first 500 KiB of the file and ignores the rest.
  • Encoding. Save as plain UTF-8 text with the name in lowercase: robots.txt.
  • Status code. A 404 for the file means 'no restrictions'. A server error (5xx) can make Google pause crawling the site.
  • Crawl-delay. Some crawlers honour it. Google ignores it.
  • Caching. Crawlers cache the file, often for up to a day, so changes may take a while to be noticed.
  • AI crawlers. Many publishers now add groups for specific AI user-agents. Each one needs its own User-agent line.

Before you publish

  1. Open the file in a browser at yoursite.com/robots.txt to confirm it loads.
  2. Search for `Disallow: /` with nothing after the slash, and be sure it is meant.
  3. Test your important URLs in the robots.txt report or tester in Search Console.
  4. Add the Sitemap line with the full https address.
  5. Recheck after every redesign or move to a new server.

Questions people ask

What is robots.txt?

It is a text file at the root of a website that tells crawlers which paths they may or may not fetch. It uses the directives User-agent, Disallow, Allow and Sitemap.

Does Disallow remove a page from Google?

Not reliably. It stops crawling, but the address can still be listed if other pages link to it. To keep a page out of results, use a noindex tag on a page that is not blocked.

What does Disallow: / do?

It blocks the entire site for the crawlers in that group. A Disallow line with no value blocks nothing.

Where should robots.txt be placed?

At the root of the host, for example https://example.com/robots.txt. Files in subfolders are not read, and each subdomain needs its own.

Can I use wildcards in robots.txt?

Yes. The star matches any sequence of characters and the dollar sign marks the end of a URL. For example, Disallow: /*.pdf$ blocks addresses ending in .pdf.

Is robots.txt a security measure?

No. It is a public request that only cooperative crawlers follow. Protect private pages with a login or server access rules.