To block an AI crawler on your own server, match its user agent and answer 403: a map and return 403 in nginx, mod_rewrite in Apache 2.4. Do it after robots.txt and only for bots you really want to stop, because a user agent rule is easy to dodge and easy to overdo.
Start with robots.txt, then enforce
- robots.txt asks a bot to stay away. Bots that honour it will. See robots.txt and AI bots for a file to copy.
- A server rule enforces your choice for bots that ignore robots.txt.
- Verification tells you whether the traffic is who it says it is. See how to verify AI crawlers.
A server rule has two limits. A user agent is a header the client writes itself, so a bot that lies passes. Apache's own access control guide warns that "access control by User-Agent is an unreliable technique, since the User-Agent header can be set to anything at all". And a wide rule can block bots you want, such as AI search; see whether to block AI crawlers.
Match training bots, not search or user fetchers
Most operators run separate bots for training, search and user requests. Block the first and leave the others to stay in AI answers. Tokens come from each operator's documentation.
| Operator | Training | AI search | Fetches for a person |
|---|---|---|---|
| OpenAI | GPTBot |
OAI-SearchBot |
ChatGPT-User |
| Anthropic | ClaudeBot |
Claude-SearchBot |
Claude-User |
| Perplexity | none documented | PerplexityBot |
Perplexity-User |
| Meta | meta-externalagent |
Meta-WebIndexer |
meta-externalfetcher |
| Common Crawl | CCBot |
none | none |
Sources: OpenAI, Anthropic, Perplexity, Meta and Common Crawl. Meta says meta-externalagent crawls "to train foundation AI models or to improve products by indexing content directly", so it is not training only. Perplexity says PerplexityBot "is not used to crawl content for AI foundation models".
Two tokens never appear as a user agent, so a server rule for them does nothing:
- Google-Extended. Google says it "doesn't have a separate HTTP request user agent string". It is a robots.txt token only. See Google-Extended.
- Applebot-Extended. Apple says it "does not crawl webpages". It only governs how data crawled by Applebot is used. Use robots.txt.
Do not match "bot" alone: that also blocks Googlebot and Bingbot.
Fetchers that act for a person may not follow robots.txt. OpenAI says "robots.txt rules may not apply" to ChatGPT-User, and Meta says meta-externalfetcher may bypass it. A server rule is the only block that reaches them, and it also stops people who asked an assistant to read your page.
nginx
Put the map in the http block and the check in the server block.
# http block
map $http_user_agent $ai_agent {
default 0;
"~*(GPTBot|ClaudeBot|CCBot|meta-externalagent)" 1;
}
# Let every bot read robots.txt, so it can see your rules.
map "$ai_agent:$uri" $block_ai {
default 0;
"1:/robots.txt" 0;
"~^1:" 1;
}
# server block
server {
# ... your existing listen, server_name, root and locations
if ($block_ai) {
return 403;
}
}
The ~* prefix makes the match case-insensitive (nginx map documentation). nginx checks the exact string 1:/robots.txt before the regular expression, so robots.txt stays readable. The if sits at server level so it covers every location; inside location / alone it would miss requests a more specific location handles. A return inside if is the safe use. Run nginx -t, then reload.
Apache 2.4
Use mod_rewrite, case-insensitive. The Apache documentation says to put such rules in the main server configuration rather than .htaccess, which is read on every request. Put this inside your VirtualHost:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (GPTBot|ClaudeBot|CCBot|meta-externalagent) [NC]
RewriteCond %{REQUEST_URI} !^/robots\.txt$
RewriteRule .* - [F,L]
[F] answers 403 and [L] stops further rules. The second condition keeps robots.txt readable.
We do not suggest a Require block in a site-wide <Location>: Apache merges <Location> sections after directory and .htaccess rules, so its Require lines can replace the access rules that protect private folders.
On shared hosting, put the same rewrite lines in .htaccess where the host allows it. It costs more per request, which is why the Apache documentation prefers the main file.
We tested the rewrite rules on Apache 2.4: GPTBot and claudebot got 403, OAI-SearchBot and a browser string got 200, and robots.txt answered 200 to GPTBot. We did not run the nginx config on a live server, so use nginx -t before you reload.
Test with curl and read the log
Send a request with the bot's name and one without, using your own domain.
curl -s -o /dev/null -w "%{http_code}\n" -A "GPTBot" https://example.com/
curl -s -o /dev/null -w "%{http_code}\n" -A "OAI-SearchBot" https://example.com/
curl -s -o /dev/null -w "%{http_code}\n" -A "GPTBot" https://example.com/robots.txt
You want 403, 200 and 200. The test sends the name only, so it shows what your rule does, not what the real bot receives.
To see real traffic, count status codes for a bot in your access log (the ninth field in the combined format).
grep -i "GPTBot" /var/log/nginx/access.log | awk '{print $9}' | sort | uniq -c
A blocked bot shows 403. A 200 for a name you meant to block means the rule is not matching, or a proxy changed the header; behind a CDN, also check the CDN's log. A name in a log line can be spoofed, so verify it first.
How Lundot handles this
Lundot reads requests at Cloudflare, so verified AI requests need a site behind Cloudflare; it does not read server logs. The free AI crawler check works for any site and reads your live robots.txt for each bot, but it will not show your server rule. See Connect Cloudflare and the AI bots report.
Sources
- OpenAI: Overview of OpenAI crawlers, read 18 November 2026
- Anthropic: Does Anthropic crawl data from the web, and how can site owners block the crawler?, read 18 November 2026
- Perplexity: Perplexity crawlers, read 18 November 2026
- Google: List of Google's common crawlers, read 18 November 2026
- Apple: About Applebot, published 4 September 2026
- Meta: Web crawlers, read 18 November 2026
- Common Crawl: FAQ, read 18 November 2026
- nginx: ngx_http_map_module, read 18 November 2026
- Apache HTTP Server 2.4: Access control, read 18 November 2026
- Apache HTTP Server 2.4: .htaccess files, read 18 November 2026
- Apache HTTP Server 2.4: mod_setenvif, read 18 November 2026