[英]Apache 2.2 - “Allow from” only if QUERY_STRING matches
我试图将我的一台服务器限制为仅一个特定的请求,但是经过2个小时的尝试后仍无法提出有效的解决方案。 基本上,我正在寻找类似于<If ...>
指令的内容,但是我只有Apache 2.2(这是事实,我无法更新为2.4)。
我有4台服务器:frontend [1-3]和backend1。 允许frontend [1-2]在backend1上执行任何操作,但是应该仅允许frontend3发出1个特定请求。 在Apache 2.4中,它看起来像这样:
<Location />
Order allow,deny
Allow from frontend1
Allow from frontend2
<If "%{QUERY_STRING} =~ /foobar/myfunc/[^/]*$">
Allow from frontend3
</If>
</Location>
我如何在Apache 2.2中做同样的事情? 我尝试使用SetEnvIf,但是由于它没有逻辑并且混乱而且无法正常工作(我必须匹配主机和 URL,因为frontend3只允许执行“ myfunc”)。
在mod_rewrite的帮助下找到了一种方法:
RewriteEngine On
# Matching the host "frontend3"
RewriteCond %{REMOTE_ADDR} ^1\.2\.3\.4$
# Matching the request "/foobar/myfunc?do=something"
RewriteCond %{QUERY_STRING} ^do=something$
# Setting an environment variable if host & request match
RewriteRule ^/foobar/myfunc$ - [E=allowthis:1,L]
<Location />
Order allow,deny
Allow from frontend1
Allow from frontend2
Allow from env=allowthis
</Location>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.