Skip to content

Robots.txt disallow rules: how to block specific bots and paths

Learn robots.txt disallow syntax with copyable examples for blocking paths, folders and AI bots, plus how Allow precedence and noindex fit in.

A path splits in two, with a gate blocking one branch and the other staying open.How-to

A robots.txt disallow rule tells a named crawler which URL paths on your website it shouldn't fetch. If you write the rule correctly, you can control which search and AI bots crawl which folders, files and URL patterns. But one stray slash can pull a whole website out of crawling, and an empty value will block nothing.

The syntax is small. Most mistakes come from three things people misremember: which group a bot reads, how paths match, and what a block does to indexing.

Robots.txt disallow syntax at a glance

Every rule sits under a User-agent line and takes the form Disallow: [path]. The path starts with / and is case-sensitive. These are the five patterns you'll use most:

Block every crawler from the whole website:

User-agent: *
Disallow: /

Block one directory (the trailing slash marks it as a folder):

User-agent: *
Disallow: /private/

Block a single file:

User-agent: *
Disallow: /private_file.html$

Add Disallow: /private_file.html? to cover query-string variants.

Block one bot only, here Googlebot:

User-agent: Googlebot
Disallow: /drafts/

Allow everything with an empty Disallow:

User-agent: *
Disallow:

How to write disallow rules step by step

Follow a fixed order when writing disallow rules. Find the file at the root, group rules under user agents, add Disallow paths, carve exceptions with Allow, then test before the change goes live.

A user-agent and path determine which crawl requests are stopped by a robots.txt disallow rule.
Pick the bot group first, then match the requests under the path you intend to block.

1. Find or create your robots.txt file

Robots.txt only works at the root of the host it governs. For www.example.com , the file lives at www.example.com/robots.txt, and Google's robots.txt creation guide says it can't sit in a subdirectory. So, a file at example.com/folder/robots.txt will get ignored. Rules also apply only to the exact host, protocol and port, so https://www.example.com/robots.txt doesn't cover https://example.com/ or http://example.com/.

To read any website's rules, add /robots.txt to its domain in a browser. That shows how competitors or your own staging environment are set up.

Where you edit the file depends on your platform:

  • WordPress serves a virtual file by default with Disallow: /wp-admin/ and Allow: /wp-admin/admin-ajax.php. Uploading a physical robots.txt to the root replaces it, and developers can change the virtual output with the robots_txt filter.
  • Yoast SEO puts an editor under Yoast SEO > Tools > File editor, where you click Create robots.txt file or edit the existing one. The menu doesn't appear if file editing is disabled in your WordPress install, in which case you edit over FTP.
  • Shopify generates a default file. To customize it, go to Online Store, choose Edit code for your theme, click Add a new template, select robots, and edit the resulting robots.txt.liquid. Shopify strongly recommends keeping its Liquid objects rather than replacing the template with plain text, because plain rules go stale.

2. Start each group with a user-agent line

A group is one or more User-agent lines followed by its rules. User-agent: * addresses every crawler that has no group of its own, so User-agent: * plus Disallow: / asks all of them to stay out. The user-agent value isn't case-sensitive, so googlebot and Googlebot match the same crawler.

Google applies exactly one group per crawler:

  • The robots.txt specification says Google's crawlers pick the group with the most specific matching user agent and ignore the rest, and the order of groups in the file doesn't matter.
  • A Googlebot group therefore replaces the * group for Googlebot. Google doesn't merge them, so any shared rule has to appear in both.
  • Two separate groups for the same bot do get combined into one.

AI crawlers each publish their own token, and vendors change these, so check the vendor page before you ship a rule. The current documented tokens are listed here:

More columns
TokenVendorWhat the vendor says it controls
GPTBotOpenAICrawling for content that may be used to train OpenAI's generative AI foundation models
OAI-SearchBotOpenAIWhether the website appears in ChatGPT search answers
Google-ExtendedGoogleUse of content for training future Gemini models and for grounding. No effect on Google Search inclusion or ranking
ClaudeBotAnthropicCollection of web content that may contribute to model training
Claude-SearchBotAnthropicIndexing used to improve Claude's search results
PerplexityBotPerplexitySurfacing and linking websites in Perplexity search results
Applebot-ExtendedAppleUse of Applebot-crawled data to train Apple's foundation models. It doesn't crawl pages itself
CCBotCommon CrawlCommon Crawl's crawler

The split matters. Blocking GPTBot signals that your content shouldn't be used to train OpenAI's generative AI foundation models. Allowing OAI-SearchBot leaves you eligible for ChatGPT search, and OpenAI says each setting is independent. User-triggered fetchers such as ChatGPT-User and Perplexity-User may not follow robots.txt at all, because a person requested the page.

3. Block the whole website or nothing at all

Disallow: / and Disallow: look almost identical and do opposite things. The slash matches every path, so the first blocks the entire website. The empty value matches nothing. Google's useful rules page says an empty Disallow allows all crawlers into the whole website, the same as having no file or writing Allow: /.

Protect staging with a password rather than a Disallow: / rule, because a password stops crawlers whether or not they read robots.txt. The classic accident is a staging robots.txt with Disallow: / that ships to production in a deploy. Google generally caches robots.txt, so a fix won’t take effect the moment you upload it.

4. Block a directory or a single file

Disallow paths match by prefix from the first character of the path. That's why the trailing slash on a directory is worth typing. Disallow: /private/ blocks everything inside the folder. Disallow: /private also blocks /private-notes.html and /privateer/, because they start with the same characters.

Paths are case-sensitive too. Google's specification shows that /fish matches /fish.php?id=anything but not /Fish.asp or /catfish. If your CMS serves both /Blog/ and /blog/, you need a rule for each.

For an exact URL without a query string, write the full path and end it with $:

User-agent: *
Disallow: /downloads/price-list.pdf$

To block query-string variants of this file too, add Disallow: /downloads/price-list.pdf?.

5. Match URL patterns with wildcards

Google supports two wildcards in paths. * matches zero or more characters, and $ marks the end of the URL. Together they handle file types and query strings, like this:

User-agent: Googlebot
# Block every .xls file anywhere on the website
Disallow: /*.xls$

# Block any URL carrying a session ID parameter
Disallow: /*?sessionid=
Disallow: /*?*&sessionid=

The $ anchor is stricter than people expect. Google notes that https://example.com/cats.xls?personality=loki is not blocked by /*.xls$, because characters follow the extension. Also, a trailing * does nothing, so /private* behaves like /private.

Watch for over-broad patterns as well. Disallow: /*? blocks every URL with any parameter, which on many websites includes paginated category and search-filter pages you might want crawled.

6. Open subpaths with allow rules

Allow reopens a path inside a blocked folder. This group keeps crawlers out of everything except /public/:

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

When rules conflict, Google uses the most specific one, measured by the length of the rule path. If two rules are equally specific, Google uses the least restrictive, which means Allow wins.

Google's specification works through both cases:

More columns
URLRulesRule Google applies
https://example.com/pageallow: /p and disallow: /allow: /p, because it's longer
https://example.com/folder/pageallow: /folder and disallow: /folderallow: /folder, because equal-length conflicts go to the less restrictive rule
https://example.com/page.htmallow: /page and disallow: /*.htmdisallow: /*.htm, because it matches more characters

The third row catches people out. A short Allow doesn't beat a longer wildcard Disallow just because it's an Allow.

7. Test rules before going live

Before deployment, run the candidate file through Google's robots.txt parser. Test representative URLs you intend to allow and block, including the homepage, key landing pages, and relevant query-string variants. Run the checks for each crawler group you changed.

After deployment, use these Search Console tools and your access logs to confirm the served file behaves as expected:

More columns
CheckWhereWhat a correct result looks like
Is the file fetched and parsed?Search Console robots.txt reportStatus Fetched, zero issues, a recent Checked on time. Lines with errors are ignored, so fix any flagged line
Is a specific URL blocked?URL Inspection toolCrawl allowed? shows No for URLs you meant to block and Yes for everything else
Are bots obeying?Server access logsBlocked paths stop receiving requests from the named user agent after the cache refresh, while allowed paths keep getting hits

The robots.txt report only works for Domain properties or URL-prefix properties without a path. After a critical fix, use Request a recrawl from the file's menu so Google refreshes its cached copy sooner than the usual cache cycle.

An annotated sample robots.txt with multiple groups

This file blocks admin areas for everyone, gives Googlebot its own group, opts out of OpenAI training while staying in ChatGPT search, and points to the sitemap. Each comment explains the line beneath it.

# Default group: any crawler without its own group reads this
User-agent: *
# Keep crawlers out of the admin area
Disallow: /admin/
# Reopen the public help pages inside it (longer path wins)
Allow: /admin/help/
# Skip cart URLs and anything starting with /cart
Disallow: /cart
# Skip URLs carrying a session ID
Disallow: /*?sessionid=
Disallow: /*?*&sessionid=

# Googlebot group: Googlebot ignores the * group entirely,
# so the shared rules are repeated here
User-agent: Googlebot
Disallow: /admin/
Allow: /admin/help/
Disallow: /cart
Disallow: /*?sessionid=
Disallow: /*?*&sessionid=
# Googlebot only: skip PDFs that end the URL
Disallow: /*.pdf$

# Opt out of content use for OpenAI model training
User-agent: GPTBot
Disallow: /

# Stay eligible for ChatGPT search answers on public pages
User-agent: OAI-SearchBot
Disallow: /admin/
Allow: /admin/help/
Disallow: /cart
Disallow: /*?sessionid=
Disallow: /*?*&sessionid=

# Sitemap applies to all crawlers and needs a full URL
Sitemap: https://www.example.com/sitemap.xml

The Sitemap line isn't tied to any group, and you can list several. Google ignores content past 500 KiB, so a file this size is nowhere near the limit.

Disallow blocks crawling but not indexing

A disallowed URL can still show up in Google. Google's robots.txt introduction says robots.txt isn't a mechanism for keeping a page out of Google, and that Google may index a blocked URL it finds linked from elsewhere. The result appears without a description, sometimes with anchor text from the linking page.

To keep a page out of results, use noindex as a meta tag or as an X-Robots-Tag HTTP header (the header also covers PDFs and images). That only works if Google can crawl the page. Google's noindex guide says it has to crawl a page to see its tags and headers, and that noindex inside robots.txt isn't supported. A Disallow plus a noindex on the same URL is the worst combination, because the block hides the noindex.

Diagram with two paths. When crawling is allowed, Googlebot fetches the page and can read noindex. When a robots.txt rule blocks crawling, Googlebot skips the fetch and cannot read the directive.
Google can apply a page-level noindex directive only after it fetches the page.

For an already-indexed URL, restore crawl access so Googlebot can read noindex. Use temporary removal if the result needs to disappear sooner.

How to remove pages already indexed despite a disallow rule

Fixing an "Indexed, though blocked by robots.txt" page takes a short sequence:

  1. Remove the Disallow rule that covers the URL so Googlebot can fetch it.
  2. Add a noindex meta tag, or an X-Robots-Tag: noindex header for non-HTML files.
  3. Run a live test in URL Inspection and confirm that Google sees the directive. Keep the URL crawlable while Google revisits it.
  4. For faster temporary removal, submit a request in the Search Console Removals tool. If accepted, it hides the URL for about six months while Google processes the noindex.
  5. Leave crawling allowed once the page drops out. Google's removals guidance says not to use robots.txt as the blocking mechanism. Google may still index linked URLs if a re-added Disallow prevents it from reading the noindex.

If the content is gone for good, have your server return a 404 or 410 status. Removing content also protects against search engines that might not respect noindex.

Common disallow mistakes to avoid

Most broken robots.txt files fail in one of a handful of ways. Run this checklist before every deploy:

  • A Disallow: / copied from staging blocks the entire website.
  • An empty Disallow: written by someone who meant to block everything allows everything instead.
  • A path in the wrong case, such as /Private/ for a folder served as /private/, matches nothing.
  • A missing trailing slash, as in /private, blocks every path that starts with those characters, not just the folder.
  • An over-broad wildcard such as /*? blocks every parameterized URL, including pages you want crawled.
  • A Googlebot group that leaves out rules from the * group, on the assumption that Google merges them.
  • Blocked CSS and JavaScript files. Google won't render JavaScript from blocked files, so pages that depend on them get analyzed poorly.

Robots.txt is public and not a security control

Anyone can read your robots.txt, and listing a path there advertises it. RFC 9309, the Robots Exclusion Protocol, says these rules aren't a form of access authorization and that listing paths makes them discoverable. Crawlers are only requested to honor the file. Well-behaved bots from Google, OpenAI and Anthropic do, while user-triggered fetchers and scrapers that ignore the protocol won't.

So a Disallow: /internal-reports/ line hides nothing from a curious visitor. It tells them where to look. Put anything sensitive behind authentication, such as HTTP authentication or a login, and keep robots.txt for what it handles well, which is steering crawl traffic and telling AI bots how your content may be used.