How to block AI crawlers: robots.txt, Cloudflare and nginx
Short answer
Use three layers. A robots.txt file asks AI crawlers that honour it to stay away. A server or CDN rule returns 403 to crawlers that send their user agent token, such as GPTBot or ClaudeBot. Bot detection handles scrapers that pose as normal browsers, because user agent rules only stop crawlers that identify themselves.
robots.txt, a server or CDN rule and bot detection each catch traffic the previous layer misses. Decide first which kinds of AI bot you want to keep out: training crawlers, AI search crawlers, user-triggered fetchers, or all of them. Should you block AI crawlers? covers that choice, and what are AI crawlers? lists the tokens.
How to block AI crawlers with robots.txt
This file blocks the main training crawlers and, in a second group, AI search crawlers and user-triggered fetchers. Delete the second group if you want to stay visible in AI search answers.
# AI training crawlers and control tokens
User-agent: GPTBot
User-agent: ClaudeBot
User-agent: CCBot
User-agent: Bytespider
User-agent: meta-externalagent
User-agent: Amazonbot
User-agent: Google-Extended
User-agent: Applebot-Extended
Disallow: /
# AI search crawlers and user-triggered fetchers
User-agent: OAI-SearchBot
User-agent: ChatGPT-User
User-agent: Claude-SearchBot
User-agent: Claude-User
User-agent: PerplexityBot
User-agent: Perplexity-User
Disallow: /
User-agent: *
Disallow: /cart/
Disallow: /account/
Sitemap: https://www.example.com/sitemap.xmlToken matching is case-insensitive, and several User-agent lines can share one group. A crawler that finds its own group ignores the * group, so copy any * rules it should still follow into its group. Every subdomain needs its own file, and crawlers can take up to 24 hours to pick up a change.
How to block AI crawlers in nginx
Put the map in the http block. It sets a variable to 1 when the user agent contains one of the tokens, ignoring case:
map $http_user_agent $block_ai_crawler {
default 0;
# Training crawlers
~*gptbot 1;
~*claudebot 1;
~*ccbot 1;
~*bytespider 1;
~*meta-externalagent 1;
~*amazonbot 1;
# AI search crawlers and user-triggered fetchers
~*oai-searchbot 1;
~*chatgpt-user 1;
~*claude-searchbot 1;
~*claude-user 1;
~*perplexitybot 1;
~*perplexity-user 1;
~*meta-externalfetcher 1;
}
server {
listen 80;
server_name example.com;
root /var/www/example;
location = /robots.txt {
try_files $uri =404;
}
location / {
if ($block_ai_crawler) {
return 403;
}
try_files $uri $uri/ =404;
}
}The check sits inside location / so that /robots.txt stays readable. Under RFC 9309, a crawler that gets a 4xx response for robots.txt may treat the whole site as allowed and keep requesting pages. Anthropic gives a similar warning about IP blocks: they stop its bots from reading your robots.txt, so the opt-out may not hold. If you have other location blocks that serve pages, add the same if to each. Delete the second group of map lines if you want to stay in AI search, mirroring the robots.txt file. For ChatGPT-User, Perplexity-User and meta-externalfetcher, whose operators say they may not follow robots.txt, a server rule like this is the only reliable block. Run nginx -t before reloading. Apache and more nginx patterns are in how to block bots with nginx and Apache.
How to block AI crawlers with Cloudflare
Cloudflare has a managed option under Security settings, filtered to bot traffic. The setting it currently calls AI Crawler and Agent access policies lets you block or allow AI bots separately for search, agent and training behaviour, and the policy applies both to verified bots and to unverified bots that match them. A related toggle, Bot Preference Sync, writes matching lines into your robots.txt. Cloudflare renames these settings from time to time, so follow the current documentation. AI Crawl Control shows which AI crawlers visit and whether they follow your robots.txt.
For your own list, create a custom rule with the action Block and this expression:
(lower(http.user_agent) contains "gptbot"
or lower(http.user_agent) contains "claudebot"
or lower(http.user_agent) contains "ccbot"
or lower(http.user_agent) contains "bytespider"
or lower(http.user_agent) contains "meta-externalagent"
or lower(http.user_agent) contains "amazonbot")
and http.request.uri.path ne "/robots.txt"This expression covers the training crawlers. To block AI search crawlers and user-triggered fetchers as well, add their tokens from the nginx map in the same lowercase form. contains is case-sensitive, which is why the expression lowercases the user agent first. More Cloudflare options are in how to block bots with Cloudflare.
How to block AI crawlers on WordPress
WordPress serves a generated robots.txt when there is no file on disk. Upload your own robots.txt to the web root, or edit it through your SEO plugin's file editor if it has one. That covers only the robots.txt layer, so add the nginx or Apache rule, or a CDN rule, for enforcement.
Why user agent rules are not enough
A user agent rule stops only crawlers that announce themselves. A scraper collecting content for an AI dataset can send a normal Chrome user agent, run a real browser and rotate through residential IP addresses, and none of the rules above will see it. Catching that traffic needs detection based on TLS and browser fingerprints, behaviour and network signals, as described in can web scraping be detected?.
The reverse problem matters too. A request that says GPTBot may not come from OpenAI. If you allow some AI crawlers and block others, confirm the source IP against the operator's published list, as shown in how to verify good bots.
Check that the block works
curl -s -o /dev/null -w "%{http_code}\n" -A "GPTBot" https://www.example.com/
curl -s -o /dev/null -w "%{http_code}\n" -A "GPTBot" https://www.example.com/robots.txtThe first command should print 403 and the second 200. After a day, count 403 responses per token in your access logs.
Tools that help
StopBots is published by Kairal, which is one of the tools listed. The list is not a ranking.
- ai.robots.txt is an open-source, MIT-licensed list of AI crawlers with a ready robots.txt and matching configs for Apache, nginx, Caddy, HAProxy and lighttpd, enough for most small sites.
- Cloudflare AI Crawl Control shows which AI crawlers reach a site on Cloudflare and lets you allow or block each one, on all Cloudflare plans.
- Known Agents keeps a directory of AI agents and bots and offers an automatically updated robots.txt and agent analytics, with a free tier.
- Anubis is an open-source proxy that asks browsers to solve a small proof-of-work challenge before serving pages, which slows heavy scrapers that hide their identity.
- Kairal Agent Traffic Intelligence gives visibility and control over AI agents and crawlers, alongside detection for scrapers that do not identify themselves.
Common questions
Does Cloudflare block AI crawlers?
It can, through its AI crawler policies or a custom rule. Whether blocking is already on depends on how and when your zone was set up, so open the bot traffic settings in your dashboard and check the current value for search, agent and training crawlers.
Can I block AI crawlers with .htaccess?
Yes, on Apache with mod_rewrite. Add a RewriteCond on %{HTTP_USER_AGENT} that matches the tokens with the [NC] flag for case-insensitive matching, followed by RewriteRule ^ - [F], which returns 403 Forbidden.
Does blocking AI crawlers remove my content from existing AI models?
No. Blocking stops future collection by crawlers that respect it. Content collected before the block stays in datasets and models already built, and removing it depends on each operator's own process.