[英]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.