1. Websta Hosting
Backups & Security

How to Block Bad Bots and IP Addresses

How to Block Bad Bots and IP Addresses

Block a Specific IP via .htaccess

Order allow,deny
Deny from 198.51.100.0
Allow from all

Block a range:

Deny from 198.51.100.0/24

Block by User Agent (Bot Blocker)

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} "AhrefsBot|SemrushBot|MJ12bot|DotBot" [NC]
    RewriteRule .* - [F,L]
</IfModule>

Block Access to wp-admin Except Your IP

<Files wp-login.php>
    Order deny,allow
    Deny from all
    Allow from 203.0.113.10
</Files>

Using Cloudflare to Block IPs (Recommended)

If you use Cloudflare:

  1. Go to Security โ†’ WAF โ†’ Custom Rules.
  2. Create a rule: IP Source Address equals [bad IP] โ†’ Action: Block.

Cloudflare blocks at the edge, before requests reach your server.

Monitoring for Brute Force Attacks

Check your access logs via SSH:

tail -f ~/logs/yourdomain.com/access.log | grep "POST /wp-login"

Install Wordfence (WordPress) or Fail2Ban (contact support) to automatically block repeated failed logins.

Still need help?

If this article didn't answer your question, our support team can help.

Contact support
All articles More in Backups & Security