重定向范围使用的RewriteCond的IPS [英] Redirect a range of IPs using RewriteCond

查看:139
本文介绍了重定向范围使用的RewriteCond的IPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我重定向以外的所有用户的IP 12.345.678.90使用:

  RewriteEngine叙述上
的RewriteCond%{REQUEST_URI}!/维修$
的RewriteCond%{} REMOTE_HOST!^ 12 \ .345 \ 0.678 \ 0.90
重写规则$ /维修[R = 302,L]
 

什么语法我会用允许的范围?在我的允许名单上有:

 从123.45.678.90/28允许
 

将它的工作,如果我只是更新REMOTE_HOST行:

 的RewriteCond%{} REMOTE_HOST!^ 12 \ .345 \ 0.678 \ 0.90 / 28
 

解决方案

您可能希望在%{REMOTE_ADDR} 来匹配,但你不能使用CIDR标记作为%{REMOTE_ADDR} 字面上的远程地址的,你可以用一个普通的前pression尝试来匹配。所以对于123.45.67.89/28,(123.45.67.80 - 123.45.67.95),你就必须做这样的事情:

 的RewriteCond%{REMOTE_ADDR}!^ 123 \ 0.45 \ 0.67 \ 0.8 [0-9] $
的RewriteCond%{REMOTE_ADDR}!^ 123 \ 0.45 \ 0.67 \ 0.9 [0-5] $
 

Currently I am redirecting all users except for the IP 12.345.678.90 using:

RewriteEngine On
RewriteCond %{REQUEST_URI} !/maintenance$
RewriteCond %{REMOTE_HOST} !^12\.345\.678\.90
RewriteRule $ /maintenance [R=302,L]

What syntax would I use to allow a range? In my Allow list I have:

Allow from 123.45.678.90/28

Would it work if I just update the REMOTE_HOST line to:

RewriteCond %{REMOTE_HOST} !^12\.345\.678\.90/28

解决方案

You probably want the %{REMOTE_ADDR} to match against, but you can't use CIDR notation as the %{REMOTE_ADDR} is literally the remote address and you can use a regular expression to try to match against it. So for 123.45.67.89/28, (123.45.67.80 - 123.45.67.95), you'd have to do something like this:

RewriteCond %{REMOTE_ADDR} !^123\.45\.67\.8[0-9]$
RewriteCond %{REMOTE_ADDR} !^123\.45\.67\.9[0-5]$

这篇关于重定向范围使用的RewriteCond的IPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆