使用 RewriteCond 重定向一系列 IP [英] Redirect a range of IPs using RewriteCond

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

问题描述

目前我正在使用以下方法重定向除 IP 12.345.678.90 之外的所有用户:

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

如果我只是将 REMOTE_HOST 行更新为:

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

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

推荐答案

您可能希望 %{REMOTE_ADDR} 与之匹配,但您不能使用 CIDR 表示法作为 %{REMOTE_ADDR}字面意思是远程地址,您可以使用正则表达式尝试与之匹配.所以对于 123.45.67.89/28,(123.45.67.80 - 123.45.67.95),你必须做这样的事情:

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 重定向一系列 IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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