如何使用特定的RewriteCond阻止htaccess中的ip范围

时间:2015-06-07 10:11:17

标签: apache .htaccess

我创建了代理,我的链接遭到了垃圾邮件攻击。 我知道他们的IP,但我无法阻止他们访问我的网站。我的代码:

Order Allow,Deny
Deny from 64.233.172.0/24
Deny from 66.249.83.0/24
Deny from 66.102.8.0/24
Deny from 173.252.81.0/24
Deny from 173.252.100.0/24
Deny from 173.252.102.0/24
Deny from 173.252.113.0/24
Deny from 173.252.73.0/24
Deny from 173.252.75.0/24
Deny from 173.252.79.0/24
Deny from 69.171.228.120
Deny from 69.171.230.117
Deny from 69.171.235.117
Deny from 173.252.107.115
Deny from 173.252.105.117
Deny from 173.252.122.117
Deny from 173.252.114.118
Deny from 173.252.75.119
Deny from 173.252.103.5
Deny from 173.252.88.91

Allow from all

RewriteEngine On
RewriteCond $1 !^(script\.php)
RewriteBase /
RewriteRule ^(.*)$ proxy.php?url=$1 [L,QSA]

我无法删除这些必须以这种方式工作的脚本和代理文件。请告诉我如何解决这个问题?

这是我的系统配置。

Apache 2.2.29
DirectAdmin 1.48.0
Exim 4.84
MySQL 5.5.9
Named 9.7.3     
ProFTPd 1.3.5
sshd
dovecot 2.2.15
Php 5.3.29

2 个答案:

答案 0 :(得分:3)

这取决于您使用的Apache版本。

如果您使用2.2,则以下内容应该有效:

table.imagetable tr.mutated td { background-color: red; }

如果您使用的是2.4,那么您应该使用它:

Order allow,deny
Allow from all
Deny from 64.233.172
Deny from 66.249.83
# ... etc ...

如果这些都不适合您,那么您可以改为使用Require all granted Require not ip 64.233.172 Require not ip 66.249.83 # ... etc ...

mod_rewrite

更新

根据您的评论,请改为使用以下代码:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^64\.233\.172 [OR]
RewriteCond %{REMOTE_ADDR} ^66\.249\.83 [OR]
# ... etc ...
RewriteRule ^ - [F,L]

你只是按错了顺序。首先需要设置基数,然后禁止某些IP地址,只有才能进行其他重写。

答案 1 :(得分:0)

你必须开始允许所有人。你可以将整个东西放在一个极限标签中,并用A.B.C替换A.B.C.D / 24形式的范围。

<Limit GET POST>
  Order Allow,Deny
  Allow from all
  Deny from 64.233.172.
  Deny from 66.249.83.
  Deny from 66.102.8.
  Deny from 173.252.81.
  Deny from 173.252.100.
  Deny from 173.252.102.
  Deny from 173.252.113.0
  Deny from 173.252.73.
  Deny from 173.252.75.
  Deny from 173.252.79.
  Deny from 69.171.228.120
  Deny from 69.171.230.117
  Deny from 69.171.235.117
  Deny from 173.252.107.115
  Deny from 173.252.105.117
  Deny from 173.252.122.117
  Deny from 173.252.114.118
  Deny from 173.252.75.119
  Deny from 173.252.103.5
  Deny from 173.252.88.91
</Limit>