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

依然范特西╮ 提交于 2019-11-27 18:59:42

You could use:

Order Allow,Deny
Deny from 66.249.74.0/24
Allow from all

Or you could use this:

RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^66\.249\.74\.
RewriteRule ^ - [F]

Use just the first 3 octets

Order Allow,Deny
Deny from 66.249.74.
Allow from all
Vladyn

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.

antimalwareprogram

You can go to: and enter ips and it will generate the file for you. http://www.htaccesstools.com/block-ips/

Also for example you want to block the ip address range you want would be:

Order Allow,Deny
Deny from 66.249.74.0/24
Allow from all

Or You Can Do:

You can indicate which addresses you wish to block using RewriteCond %{HTTP_REFERER}.

This is a Working Example:

# BLOCK VISITORS REFERRED FROM GOOGLE.COM

RewriteCond %{HTTP_REFERER} ^https?://([a-z0-9-]+\.)?google\.com [NC]
RewriteRule .* - [F]

The example above uses a regular expression, so it will block:

  • https:// or http://
  • followed by any subdomain (or none)
  • followed by google.com
  • followed by anything (or nothing)

The [F] flag means Forbidden. The server will return a 403 Forbidden Error.

you can do it easily by adding IP Ranges to your .htaccess file by downloading the full ranges from https://www.ip2location.com/blockvisitorsbycountry.aspx and uploading the .hataccess back to the directory you want blocked.

I recently blocked Russia by this method cause of getting loads of spam registrations on my forum and the forum never needs any contribution from this country.

eg:

<Files *>
order deny,allow
deny from 2.72.0.0/13 2.92.0.0/14 2.132.0.0/14 
</Files>

Great howto with ip ranges here:

http://www.wizcrafts.net/russian-blocklist.html

Also these are up to date lists of offending ip ranges.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!