![]() |
|
Guide Block Bad Bots, Probes and IPs on a CyberPanel Website With Rewrite Rules - Printable Version +- AdminsForum (https://adminsforum.com) +-- Forum: Free & open-source control panels (https://adminsforum.com/Forum-free-open-source-control-panels) +--- Forum: CyberPanel (https://adminsforum.com/Forum-cyberpanel) +---- Forum: CyberPanel Guides & Tutorials (https://adminsforum.com/Forum-cyberpanel-guides-tutorials) +----- Forum: CyberPanel Security Guides (https://adminsforum.com/Forum-cyberpanel-security-guides) +----- Thread: Guide Block Bad Bots, Probes and IPs on a CyberPanel Website With Rewrite Rules (/Thread-guide-block-bad-bots-probes-and-ips-on-a-cyberpanel-website-with-rewrite-rules) |
Block Bad Bots, Probes and IPs on a CyberPanel Website With Rewrite Rules - JAY - 11-14-2026 Block Bad Bots, Probes and IPs on a CyberPanel Website With Rewrite Rules (Tested) Aggressive crawlers and scanners can make up most of a small site's traffic: SEO bots that hit every page, and scripts that look for Code: .envWhich web server: our test server runs LiteSpeed Enterprise. The rules are ordinary rewrite rules, the kind OpenLiteSpeed also reads from this box, but we ran these exact tests on Enterprise only. Step 1: See who is hitting your site Each website has its own access log. Over SSH, list the most common visitors by their browser name (user agent): Code: L=/home/yourdomain.com/logs/yourdomain.com.access_log
awk -F'"' '{print $6}' $L | sort | uniq -c | sort -rn | headCode: awk '$9==404{print $1}' $L | sort | uniq -c | sort -rn | headStep 2: Add the rules Open Websites → your site → Config → Rewrite Rules. Paste this block at the very top, above everything that's already there, and click Save Rewrite Rules: Code: ### Block bad bots and probes
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (AhrefsBot|SemrushBot|MJ12bot|DotBot) [NC]
RewriteRule .* - [F,L]
RewriteRule (^|/)\.(env|git) - [F,L]
RewriteCond %{REMOTE_ADDR} ^203\.0\.113\.5$
RewriteRule .* - [F,L]
### End blockWhat each part does:
Step 3: Test it From any computer with curl, pretend to be a bot with Code: -ACode: curl -s -o /dev/null -w "%{http_code}\n" -A "AhrefsBot" https://yourdomain.com/
curl -s -o /dev/null -w "%{http_code}\n" https://yourdomain.com/.envCode: Normal browser 200
AhrefsBot 403
semrushbot (lower case) 403
Googlebot 200
AhrefsBot on a page that was cached 403
/.env 403
/.git/config 403
/wp-content/.env 403
MJ12bot asking for a CSS file 403
The blocked IP address 403Code: x-litespeed-cache: hitBe careful what you block
Not sure which names to block? Reply below with the top lines from the user agent command in step 1. |