If a WordPress site on cPanel started throwing 508s or feeling slow with no change in human traffic, the raw access log will usually tell you why in about ninety seconds: some share of your uncached PHP hits now belongs to GPTBot, ClaudeBot, Bytespider, Amazonbot, meta-externalagent or PerplexityBot. That share is worth measuring before you do anything, because the decision is not “AI bots bad”. Search crawlers pay for themselves. Retrieval crawlers sometimes send you visitors. Training crawlers usually send you nothing at all and still consume an entry process per request. And whatever you decide, robots.txt will not carry it out — it is a published request that well-behaved crawlers honour and everyone else ignores, so enforcement has to live somewhere with teeth.
What you’ll accomplish
- A number, not a feeling: the exact share of your dynamic (PHP) requests that came from named AI crawlers over a real 24-hour window.
- A short list of the disguised clients — high-volume IPs sending a browser user-agent that never fetch a stylesheet or an image.
- A written policy per crawler class, with search crawlers explicitly protected from your own regex.
- Enforcement in the layer that costs the least:
.htaccesson the cPanel account, Cloudflare bot rules if the site is proxied, and rate limiting for the rest. - A
curlverification that the rule returns 403 to the bot user-agent and 200 to Googlebot and to a browser.
Prerequisites
A cPanel account with SSH or Terminal access, or at minimum the Raw Access downloads in cPanel. WordPress 6.x. Apache 2.4 or LiteSpeed/LSWS as the web server — both read .htaccess and both support mod_rewrite syntax, so the enforcement snippet below is the same on either. If the account is on CloudLinux, requests are metered as LVE entry processes and you have a Resource Usage page in cPanel; if it is not, substitute “concurrent PHP workers” everywhere below and the reasoning is unchanged.
Two stack differences change the steps. If the domain is proxied through Cloudflare, the origin sees Cloudflare’s IPs, so per-IP measurement and per-IP rate limiting at the origin are meaningless until visitor IP restoration is in place — and you should be enforcing at Cloudflare anyway. If a full-page cache (LiteSpeed Cache, WP Rocket, a CDN) is already serving crawlers from cache, most of this traffic is nearly free and your problem is somewhere else. Confirm that first.
How it works
A single request passes through several places where it could be stopped, and the further up it stops, the less it costs.
robots.txt sits at the top and is not enforcement. It is a text file the crawler chooses to read. OpenAI, Anthropic, Google and Common Crawl do read it and do stop; a scraper renting residential proxies does not. It still matters for one reason: Google-Extended and Applebot-Extended are robots.txt tokens only. They never appear in your access log as a user-agent, because the fetching is done by Googlebot and Applebot. The only way to express a preference about them is in robots.txt. You cannot block them in .htaccess — there is nothing to match.
Everything below that line is real. A Cloudflare bot rule rejects the request before it crosses the network to your server. An .htaccess rule returns 403 from the web server before PHP is started, which costs roughly what serving a small static file costs. A request that gets past both allocates a PHP worker, boots WordPress, runs your plugins and queries MySQL — that is the expensive path, the one that fills your entry process limit and produces 508 Resource Limit Reached.
The classes matter because the answer differs per class.
Step-by-step
- Find the right log file. cPanel keeps live logs per domain in
~/access-logs/, with HTTPS traffic in the-ssl_logfile — which on a modern site is nearly all of it.
ls -lS ~/access-logs/
Expect the SSL log to dominate. Set it once and reuse it:
LOG=~/access-logs/example.com-ssl_log
wc -l "$LOG"
- Rank the named crawlers. The combined log format puts the user-agent in the sixth field when you split on the double-quote character. Count each request once — a naive
grep -odouble-counts, because several of these agents repeat their own name inside the contact URL they publish.
awk -F'"' -v pats="OAI-SearchBot ChatGPT-User Claude-User Perplexity-User GPTBot ClaudeBot PerplexityBot Amazonbot Bytespider meta-externalagent CCBot Applebot Googlebot bingbot" '
BEGIN { n = split(pats, p, " ") }
{ ua = tolower($6)
for (i = 1; i <= n; i++) if (index(ua, tolower(p[i]))) { c[p[i]]++; break } }
END { for (k in c) printf "%8d %s\n", c[k], k }' "$LOG" | sort -rn
A site with a crawler problem looks roughly like this — note that the training crawlers outweigh the search crawlers by an order of magnitude:
184220 GPTBot
96431 Bytespider
71155 ClaudeBot
40218 meta-externalagent
33907 Googlebot
19844 Amazonbot
12660 PerplexityBot
4102 bingbot
1178 ChatGPT-User
- Convert that into the number that matters: share of dynamic hits. Static files are cheap; PHP requests are what consume workers. Filter the asset extensions out and compare.
PHPHITS=$(awk -F'"' '$2 !~ /\.(css|js|png|jpe?g|gif|svg|webp|woff2?|ico|map)([?[:space:]]|$)/' "$LOG" | wc -l)
BOTHITS=$(awk -F'"' '$2 !~ /\.(css|js|png|jpe?g|gif|svg|webp|woff2?|ico|map)([?[:space:]]|$)/ {print $6}' "$LOG" \
| grep -ciE 'GPTBot|OAI-SearchBot|ChatGPT-User|ClaudeBot|Claude-User|PerplexityBot|Perplexity-User|Amazonbot|Bytespider|meta-externalagent|CCBot')
awk -v b="$BOTHITS" -v p="$PHPHITS" 'BEGIN{printf "AI crawlers: %d of %d dynamic hits (%.1f%%)\n", b, p, 100*b/p}'
The success signal is a percentage you can put in a sentence:
AI crawlers: 424528 of 611903 dynamic hits (69.4%)
At 69 % you have your answer. At 4 % you have a curiosity, not a cost, and you should stop here. Cross-check it against the account’s Resource Usage page in cPanel: if entry-process faults line up in time with the crawler’s busiest hours, the correlation is real.
- Find the busiest hour, because averages hide bursts. Entry-process limits are about concurrency, not daily totals.
grep -iE 'GPTBot|ClaudeBot|Bytespider|Amazonbot|meta-externalagent' "$LOG" \
| awk -F'[][]' '{print substr($2,1,14)}' | sort | uniq -c | sort -rn | head -5
Output is hourly counts such as 41207 24/Aug/2026:03. A single crawler doing forty thousand requests in one hour is what trips the limit while the daily average looks calm.
- Look for the ones that lie. Some scrapers send a normal Chrome user-agent. You cannot identify them by name, but you can identify them by behaviour: a real browser loads the page and its stylesheets, fonts and images. A scraper fetches HTML only.
awk -F'"' '$6 ~ /Chrome|Firefox|Safari/ {split($1,f," "); ip=f[1]; total[ip]++;
if ($2 ~ /\.(css|js|png|jpe?g|gif|svg|webp|woff2?)([?[:space:]]|$)/) assets[ip]++}
END {for (i in total) if (total[i] > 200 && assets[i]*20 < total[i])
printf "%-16s %7d hits %6d assets\n", i, total[i], assets[i]}' "$LOG" | sort -k2 -rn | head -20
Any IP with thousands of hits and near-zero asset fetches is automated, whatever it claims to be. Be honest with yourself about this list: no user-agent rule you write will ever match these clients. They are a rate-limiting problem, not a filtering problem.
- Decide per class before writing a single rule. Check whether the retrieval crawlers are actually earning their keep:
awk -F'"' '{print $4}' "$LOG" | grep -icE 'chatgpt\.com|perplexity\.ai|copilot\.microsoft\.com'
If that returns a meaningful number of referrals, blocking ChatGPT-User and Perplexity-User costs you real visits — those user-agents fetch a page because a person asked about it, and the answer often links back to you. If it returns zero over a full month, they are just more load. Training crawlers such as GPTBot, ClaudeBot, CCBot and Bytespider send no traffic back by design; that is the class where a block is nearly free to you.
- Publish the polite layer. Edit
public_html/robots.txt(if a plugin generates it virtually, use that plugin’s field instead). This is where you express the preference that onlyrobots.txtcan carry:
User-agent: GPTBot
Disallow: /
User-agent: ClaudeBot
Disallow: /
User-agent: CCBot
Disallow: /
User-agent: Google-Extended
Disallow: /
User-agent: Applebot-Extended
Disallow: /
Verify it is actually served, and that WordPress is not overriding it:
curl -s https://example.com/robots.txt | head -20
- Enforce in
.htaccess. Put this block at the very top ofpublic_html/.htaccess, above the# BEGIN WordPressmarker — WordPress rewrites everything between those markers whenever permalinks are saved.
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (GPTBot|ClaudeBot|CCBot|Bytespider|Amazonbot|meta-externalagent) [NC]
RewriteRule ^ - [F,L]
[F] returns 403 without invoking PHP. Note what is deliberately absent: no bare bot, no AI, no Google. A condition like RewriteCond %{HTTP_USER_AGENT} bot [NC] matches Googlebot, bingbot, Applebot, your uptime monitor and your payment gateway’s webhook checker. That mistake is far more expensive than the crawler traffic you were trying to remove.
- Enforce at Cloudflare if the site is proxied. Blocking at the edge means the request never reaches your server at all. Under Security > Bots, the Block AI Scrapers and Crawlers toggle is available on every plan including the free one. For finer control, add a WAF custom rule with an expression that cannot touch verified search engines:
(http.user_agent contains "GPTBot" or http.user_agent contains "Bytespider") and not cf.client.bot
- Rate-limit the remainder. Everything in step 5 — plus any named crawler you chose to allow but not to allow unlimited — needs a ceiling rather than a block. At the origin that is mod_evasive on cPanel; at the edge it is a Cloudflare rate-limiting rule. A limit of a few requests per second per IP leaves humans untouched and turns a crawl burst into a slow trickle.
Validate it works
Test the exact user-agent strings, from a machine outside the server. First the bot you meant to block:
curl -s -o /dev/null -w '%{http_code}\n' \
-A "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; GPTBot/1.2; +https://openai.com/gptbot" \
https://example.com/
Expected: 403. Now the two things you must not have broken:
curl -s -o /dev/null -w 'googlebot %{http_code}\n' \
-A "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" https://example.com/
curl -s -o /dev/null -w 'browser %{http_code}\n' \
-A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" \
https://example.com/
Expected: googlebot 200 and browser 200. Then confirm from the log side after a day, by re-running step 3 and watching the percentage fall, and by checking that 403s are going to the right agents:
awk -F'"' '$3 ~ / 403 / {print $6}' "$LOG" | sort | uniq -c | sort -rn | head
Finally, open Google Search Console and run URL Inspection > Test Live URL on the home page. It must fetch successfully. Watch Settings > Crawl stats for a week; a drop in Googlebot success rate means your regex is wrong, not that Google lost interest.
Troubleshooting
The rule does nothing after a permalink save. The block was inside the # BEGIN WordPress / # END WordPress markers and WordPress regenerated the file. Move it above the opening marker and re-test with curl -A.
Traffic barely dropped. Re-run step 5. If the volume is coming from clients sending a Chrome user-agent, no user-agent rule will ever reach them — that is the honest limit of this technique. Move that traffic to rate limiting or edge bot scoring, and accept that identification by name only works on crawlers that choose to be identifiable.
Googlebot disappeared from Search Console. Almost always a substring match: bot, spider, crawl or Google somewhere in the condition. Remove the rule, confirm 200 with the Googlebot curl above, then rewrite the condition with full crawler names only. Verify any IP claiming to be Googlebot with forward-confirmed reverse DNS — host <ip> should resolve to googlebot.com or google.com, and the resulting name must resolve back to the same IP. The Google crawlers overview lists every official agent and token.
Real visitors are getting 403. Run the last command in the validation section. If the blocked agents are browser strings, your regex matched something common — AI inside Mozilla/5.0 (Linux; ...) style fragments is a classic. Tighten to word-anchored crawler names.
Behind Cloudflare, per-IP measurement shows one IP with all the traffic. That is Cloudflare, not a bot. Restore the visitor IP at the origin before drawing conclusions, or do the whole analysis in Cloudflare’s own analytics instead.
A crawler you blocked still appears in the log. With [F] it will — it now receives a 403 instead of a rendered page. That is the win: the line in the log costs you a log line, not a PHP worker. Compare bytes served, not request counts.
When this is the wrong approach
If step 3 returned a single-digit percentage, close the terminal. Crawler noise that fits comfortably inside your resource limits is not a problem, and every rule you add is something that can misfire during an incident at 2 a.m.
If the site has no working page cache, AI crawlers are not your issue — they are the symptom that exposed it. A cached page served to a crawler costs almost nothing. Fix caching first and re-measure; the percentage will stay the same but the cost will not.
If your goal is licensing or attribution rather than server load, none of this achieves it. robots.txt and .htaccess are operational controls, not legal ones, and blocking a training crawler after your content has been crawled for two years changes nothing about what was already collected. That is a conversation with counsel, not with Apache.
And if the business wants to be found inside answer engines, blocking the retrieval class is self-harm. Check the referrer numbers from step 6 before you write that rule. The OpenAI crawler documentation is explicit about which of its agents does which job — read it before deciding, because the two are easy to confuse and the consequences are not symmetric.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.