New: 500+ free SEO and AI search tools, no sign-up.Explore tools →

Robots.txt Guide: Rules, Examples and Common Mistakes

By Hasnain Sanmal

Robots.txt is a small text file that tells search engine bots which parts of your site they may crawl. One wrong line can stop Google from crawling your whole website, so it is worth understanding properly. This guide uses plain examples.

Free tools for this guide

Where it lives

The file must be at the root of the domain: https://yoursite.com/robots.txt. A robots.txt in a subfolder is ignored. Each subdomain (for example shop.yoursite.com) needs its own file.

The four rules you need

  • User-agent: which bot the rules apply to. * means all bots.
  • Disallow: a path the bot should not crawl.
  • Allow: an exception inside a disallowed folder.
  • Sitemap: the full URL of your XML sitemap.

Google also understands * as a wildcard and $ for “ends with”. It ignores Crawl-delay.

A safe WordPress example

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /?s=
Disallow: /search/

Sitemap: https://yoursite.com/sitemap_index.xml

This keeps bots out of the admin area and internal search results, while leaving everything else open.

An online store example

User-agent: *
Disallow: /cart/
Disallow: /checkout/
Disallow: /my-account/
Disallow: /*?orderby=
Disallow: /*?filter_

Sitemap: https://yourstore.com/sitemap_index.xml

Blocking sort and filter URLs stops Google wasting crawl time on thousands of near-duplicate pages.

The biggest misunderstanding

Robots.txt controls crawling, not indexing. If other sites link to a blocked URL, Google can still index it, usually with no description. To keep a page out of search results, allow crawling and add a noindex meta robots tag instead. Google has to crawl the page to see that tag.

Common mistakes

  • Disallow: / left on after launch. Developers often block the whole site on staging, then forget. Also check that WordPress “Discourage search engines” is turned off.
  • Blocking CSS and JavaScript. Google needs them to render your pages and judge mobile-friendliness.
  • Using robots.txt to hide private pages. The file is public, so it can point people straight to them. Use passwords instead.
  • Typos in paths. Rules are case-sensitive: /Blog/ and /blog/ are different.
  • Forgetting the sitemap line. It is an easy way to help bots find your pages.

How to test your file

  1. Paste your rules and a few important URLs into the Robots.txt Tester.
  2. Make sure your home page, main service pages and blog posts show as allowed.
  3. In Google Search Console, open Settings and check the robots.txt report for fetch errors.
  4. Use URL Inspection on a key page to confirm “Crawl allowed: Yes”.

What about AI bots?

You can add separate rules for AI crawlers such as GPTBot, ClaudeBot and PerplexityBot. Read our llms.txt and AI crawler guide before you block them, because for most businesses being cited by AI is useful visibility.

Frequently asked questions

What does robots.txt do?

Robots.txt tells crawlers which paths of a site they may crawl. It controls crawling, not indexing.

Can robots.txt remove a page from Google?

No. To keep a page out of search results, allow crawling and add a noindex tag instead.

Should I block AI crawlers in robots.txt?

It depends on your goals. Blocking AI search crawlers can stop your content from being cited in AI answers, so many sites allow search bots and only limit training bots.

Hasnain Sanmal
Hasnain Sanmal

SEO and guest post outreach specialist with 2000+ completed orders and a list of 1000+ hand-picked, high-authority websites. More about me

Need high-authority backlinks?

Get niche-relevant guest posts from my own outreach list of 1000+ websites.

Chat on WhatsApp

More to read

All articles