尝试通过IP范围将URLredirect到另一个页面

我在这里遇到了一些麻烦。 我有这几个重写规则,我认为不起作用。

我的主要目的是限制页面,只允许特定的IP或networking块。

RewriteEngine On RewriteLog "/data/wre/var/logs/modrewrite.log" RewriteLogLevel 5 RewriteCond %{REMOTE_ADDR} !^192\.168\.10\..* RewriteCond %{REMOTE_ADDR} !^72\.139\.201\..* RewriteCond %{REMOTE_ADDR} !^129\.233\.4\..* RewriteCond %{REMOTE_ADDR} !^208\.118\.97\32 RewriteRule ^/solutions https://example.com/account/signin?go=outside [R,NE,NC] 

我再次testing,似乎不工作? 我做错了吗?

尝试这个:

 RewriteEngine On RewriteLog "/data/wre/var/logs/modrewrite.log" RewriteLogLevel 5 RewriteCond %{REMOTE_ADDR} ^192\.168\.10\..* [OR] RewriteCond %{REMOTE_ADDR} ^72\.139\.201\..* [OR] RewriteCond %{REMOTE_ADDR} ^129\.233\.4\..* [OR] RewriteCond %{REMOTE_ADDR} ^208\.118\.97\.32 RewriteRule ^/solutions https://example.com/account/signin?go=outside [NE,NC,R=301] 

请注意,多个RewriteCond指令隐含AND'd,你需要指定是否应该OR'd。 如果您希望浏览器记住redirect,指定永久redirect可能会节省一些将来的处理。

根据您的configuration,指定已知良好范围和其他人redirect可能更容易。 从重写外国人的改写手册: Apache手册

 RewriteEngine on RewriteCond %{REMOTE_HOST} !^.+\.ourdomain\.com$ RewriteRule ^/solutions https://example.com/account/signin?go=outside [NE,NC,R=301] 

Prix​​,我其实是跟着这个。

http://www.the-art-of-web.com/system/rewrite/

 Conversely, you may want to allow only certain IP addresses to access the site: RewriteCond %{REMOTE_ADDR} !^12\.34\.56\.78$ RewriteCond %{REMOTE_ADDR} !^87\.65\.43\.21$ RewriteCond %{REQUEST_URI} !^sorry\.html RewriteRule .* /sorry.html Translation: IF their IP address is not 12.34.56.78 AND their IP address is not 87.65.43.21 AND the request is not for sorry.html THEN display the sorry.html page 

这2个应该设置在VirtualHostDirectory来解决:

 RewriteLog "/data/wre/var/logs/modrewrite.log" RewriteLogLevel 5 

你可以尝试你想这样的:

 RewriteCond %{REMOTE_ADDR} ^192\.168\.10\. [OR] RewriteCond %{REMOTE_ADDR} ^72\.139\.201\. [OR] RewriteCond %{REMOTE_ADDR} ^129\.233\.4\. [OR] RewriteCond %{REMOTE_ADDR} ^208\.118\.97\.32$ 

这将转化为:

  • 如果IP从192.168.10开始。
  • 或者IP从72.139.201开始。
  • 或者IP以129.233.4开头。
  • 或者IP是208.118.97.32

也许我误解了你想要做的事情,但是如果我明白你想做的事,看起来你正在以一种非常复杂的方式做事。

如果是针对整个站点或整个目录,为什么不适合在虚拟主机节的目录中使用allow指令?

http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#allow

并将403错误页面设置为sorry.html http://httpd.apache.org/docs/2.2/mod/core.html#errordocument

所以像这样:

 <directory "/path/to/content/" > Order Allow,Deny Allow 192.168.0.0/255.255.0.0 # allow everyone from the 192.168.0.0/255.255.0.0 network # every one else gets denied (default for stuff that has not matched is to the # last clause of the Order directive # the error document for a 403 (forbidden) is the sorry.html page ErrorDocument 403 /sorry.html </directory> 

看起来您正在创build一个窗帘(login墙,付费墙或维护窗帘等),除了互联网上的几个IP范围外,

这就是我所做的创build这样的configuration:

 # This implements a maintenance curtain; only these three IPs # can look behind the curtain. Note its useful to allow the box # itself too. # RewriteEngine On RewriteCond %{REMOTE_ADDR} !127.0.0.1 RewriteCond %{REMOTE_ADDR} !123.234.45.6 RewriteCond %{REMOTE_ADDR} !123.234.45.78 RewriteCond %{REQUEST_URI} !^/maintenance-curtain/.* RewriteRule / / [L,R=503] ErrorDocument 503 /maintenance-curtain/index.html ProxyPass /maintenance-curtain ! Alias /maintenance-curtain /var/www/maintenance-curtain 

这看起来和你的很相似。 我build议你先简单testing一个IP。 如果其余的如果你的configuration相当复杂,它可能会阻碍,所以请尝试在较小的上下文中certificate这一点,或者在configuration中尽早移动它。 虚拟主机正在阻碍 你是否需要复制configuration(如果需要,可以使用Include )。

我会说,虽然我有(我认为)已知的东西,如REMOTE_ADDR不会被设置的情况下,其他一些模块没有启用….一段时间,因为我触发了这种行为…是启用cgi_module?