How to Create a Robots.txt File: Rules, Examples and Mistakes

Example robots.txt file with User-agent, Disallow, Allow and Sitemap rules

A robots.txt file is a short text file that tells search engine and AI crawlers which parts of your site they may crawl. It is one of the smallest files on a website and one of the easiest to get badly wrong: a single line can hide an entire site from Google. This guide explains how to create a robots.txt file, how crawlers read it, ready-to-use examples for WordPress and Blogger, and the mistakes I see most often when auditing sites.

If you just want a working file, use our free robots.txt generator and test it before you upload it.

What Is a Robots.txt File?

A robots.txt file lives at the root of a domain, for example https://example.com/robots.txt. Well-behaved crawlers download it before crawling and follow its rules. The format was formalised as the Robots Exclusion Protocol in RFC 9309 in 2022, and Google documents exactly how it reads the file in Google’s robots.txt specification.

Two things robots.txt is not:

  • Not a security tool. The file is public and only asks crawlers to stay away. Protect private pages with a login, not with robots.txt.
  • Not an indexing control. It controls crawling. A blocked page can still appear in search results (without a description) if other sites link to it. Use a noindex meta tag on a crawlable page to keep it out of the index.

The Basic Rules

A robots.txt file is made of groups. Each group starts with one or more User-agent lines, followed by Disallow and Allow rules:

User-agent: *
Disallow: /cart/
Disallow: /checkout/
Allow: /cart/help

Sitemap: https://example.com/sitemap.xml
FieldMeaning
User-agentWhich crawler the group is for. * means every crawler without its own group
DisallowA path the crawler should not crawl. An empty value (Disallow:) means nothing is blocked
AllowAn exception inside a blocked folder
SitemapThe full URL of an XML sitemap. It can appear anywhere in the file and applies to all crawlers

How Crawlers Decide What Is Blocked

This is where most confusion comes from. According to Google’s robots.txt specification:

  • One group per crawler. A crawler follows only the group with the most specific user-agent that matches it. If there is a User-agent: Googlebot group, Googlebot ignores the User-agent: * group completely, so rules are not inherited.
  • The longest matching rule wins. For /shop/sale, the rule Allow: /shop/sale beats Disallow: /shop/ because it is more specific.
  • Ties go to Allow. If an Allow and a Disallow rule match with the same length, Google uses the less restrictive one.
  • Two wildcards are supported. * matches any characters and $ marks the end of the URL, so Disallow: /*.pdf$ blocks URLs ending in .pdf.
  • Paths are case-sensitive, but field names and user-agent names are not. /Blog/ and /blog/ are different paths.

You can check any URL against these rules in the tester tab of our robots.txt generator, which shows the exact line that decides the result.

How to Create a Robots.txt File Step by Step

  1. List what should not be crawled. Admin areas, internal search results, cart and checkout pages, and filter or sort URLs that create endless duplicates are typical candidates.
  2. Keep everything that builds your pages open. Do not block CSS, JavaScript or image folders; Google needs them to render pages.
  3. Write the file. Use a plain text editor or a generator, save it as robots.txt in UTF-8, and add your sitemap URL.
  4. Upload it to the root of the domain. A file in a subfolder is ignored, and each subdomain needs its own file.
  5. Test it. Check your most important pages and a few URLs you meant to block. Then check the robots.txt report in Google Search Console.

Robots.txt Examples

Allow everything

User-agent: *
Disallow:

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

WordPress

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

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

admin-ajax.php stays open because themes and plugins use it on public pages. Do not add /wp-content/ or /wp-includes/; they contain the CSS and JavaScript Google needs.

Blogger

User-agent: *
Disallow: /search
Allow: /

Sitemap: https://yourblog.blogspot.com/sitemap.xml

/search covers label and search result pages, which mostly repeat your posts. If you moved from Blogger, see our Blogger settings guide for where to set a custom robots.txt.

Block a staging site

User-agent: *
Disallow: /

Use this only on a test copy, ideally together with password protection. Forgetting to remove it when the site goes live is one of the most damaging SEO mistakes.

Should You Block AI Crawlers?

AI companies use separate user-agent tokens, so you can choose per company and per purpose. Blocking a training crawler does not affect Google Search: Google’s Google-Extended documentation states that Google-Extended is not used for inclusion or ranking in Google Search.

# Block AI training, keep search crawlers
User-agent: GPTBot
Disallow: /

User-agent: Google-Extended
Disallow: /

User-agent: ClaudeBot
Disallow: /

Search-style AI crawlers such as OAI-SearchBot and Claude-SearchBot are different: blocking them can remove your pages from those assistants’ answers, according to OpenAI’s crawler overview and Anthropic’s crawler help page. Many publishers block training crawlers but keep search crawlers open so they can still be cited and linked.

Common Robots.txt Mistakes

MistakeWhat happensFix
Disallow: / left from stagingThe whole site stops being crawledChange it to Disallow: or remove the line
Using robots.txt to hide a page from GoogleThe URL can still be indexed without contentAllow crawling and add a noindex meta tag
Noindex: lines in robots.txtIgnored: Google does not support this ruleUse the robots meta tag or X-Robots-Tag header
Blocking CSS and JavaScriptGoogle cannot render pages correctlyRemove those Disallow lines
Typos such as DisalowThe rule is silently ignoredValidate the file
Expecting * rules to apply to Googlebot when it has its own groupGooglebot ignores the * groupRepeat the rules inside the specific group
Relying on Crawl-delay for GoogleGoogle ignores itFix server capacity; Google adjusts its crawl rate automatically
Relative sitemap URLThe sitemap line is invalidUse the full https:// URL

If an important page is blocked by mistake, fix the file and then use URL inspection in Google Search Console. Our guide on using Google Search Console to update old content shows that workflow.

How Google Handles Errors and Changes

  • If robots.txt returns a 404 or other 4xx error (except 429), Google treats the site as having no restrictions.
  • If it returns a 5xx error, Google pauses crawling and can use the last good copy, so server errors on this file are serious.
  • Google generally caches the file for up to 24 hours, so changes take time to apply.
  • Google reads only the first 500 KiB of the file.

These details come from Google’s robots.txt specification.

Frequently Asked Questions

Do I need a robots.txt file?

Not strictly. Without one, crawlers assume everything may be crawled. It is still worth having a small file with your sitemap URL and any sections you want kept out of crawling.

Does robots.txt affect rankings?

Not directly. It affects which pages can be crawled; blocking important pages or the resources they need can hurt how they appear in search.

What is the difference between robots.txt and a noindex tag?

Robots.txt controls crawling for whole paths. A noindex tag controls indexing for a single page, and Google must be able to crawl the page to see it.

How do I block only one crawler?

Add a group for that crawler, for example User-agent: GPTBot followed by Disallow: /. Other crawlers are not affected.

Does Google support Crawl-delay?

No. Google ignores Crawl-delay. Some other crawlers, such as Anthropic’s, say they support it.

Final Thoughts

A good robots.txt file is short: block only what truly should not be crawled, keep resources open, list your sitemap and test before you publish. Create and check yours with our free robots.txt generator and tester, and explore more in the Blogging and SEO guide.

Leave A Comment

Scroll to top