working - redirect ip address htaccess




Blocking IP range in htaccess file (4)

I'm managing a site and the site is built in Wordpress. It gets ENORMOUS amount of traffic from bots and we want to block all of them except for important bots like Google Yahoo Bing Baidu. We use cloudflare and I want to block them from two layers, Cloudflare firewall and htaccess file. In htaccess file, I know how to block a single IP address and last trailing IPs of a IP range like 123.123.123.0/16

However, I need to block following IPs 69.30.192.0 - 69.30.255.255 93.55.115.64 - 93.55.115.71

How do you set rules of this in htaccess file? Cloudflare seems to follow same rule.


I’ve just used

Order Allow,Deny
Deny from 188.143.*.*
Allow from all

as spam attack comes from xxx.xxx.0-80.0-80.


Not sure how reliable the source is, but this is from clockwatchers

http://www.clockwatchers.com/htaccess_block.html

To Block a single ip address

order allow,deny
deny from 127.0.0.1
allow from all

This will refuse all GET and POST requests made by IP address 127.0.0.1, an error message is shown instead

To block multiple ip addresses, list them one per line

order allow,deny
deny from 127.0.0.1
deny from 127.0.0.2
deny from 127.0.0.3
allow from all

To block an entire ip range

deny from 127.0.0

This will refuse access for any user with an address in the 127.0.0.0 to 127.0.0.255 range.

Edit: Just found a similar question here

How to Block an IP address range using the .htaccess file

Looks like out answers are similar too.


Use just the first 3 octets

Order Allow,Deny
Deny from 66.249.74.
Allow from all

You've almost got it. The /16 notation is actually called CIDR Notation.

The number indicates how many bits to match from left to right. The Wiki page explains it in depth.

Or... you can just take my word for it and use a tool like this one I found: http://www.ipaddressguide.com/cidr#range

You can then use the deny from in your .htaccess just as you would for a single ip with the given values:

Order Allow,Deny
Deny from 69.30.192.0/18
Deny from 93.55.115.64/29
Allow from all