我有一个类似的问题:http://www.tek-tips.com/viewthread.cfm?qid=1144803
如果触发了特定操作,我正在尝试授予访问权限RewriteRule
。使用标志设置变量[E]
,但在执行后续授权步骤时,该变量似乎未设置。
无条件SetEnv let_me_in
也不起作用,但令人惊讶的是,SetEnvIf
它确实起作用。
<Directory "/srv/http">
Require env let_me_in
</Directory>
<Directory "/srv/http/html">
RewriteRule ^hello/dostuff/(.*)$ /cgi-bin/hello.sh?anon=1&x=$1 [B,E=let_me_in]
</Directory>
<Location /hello/>
Require all granted
</Location>
SetEnvIf Request_URI "(^.*$)" RURI=$1
ErrorLog "/var/log/httpd/error_log"
LogLevel debug
ErrorLogFormat "[%t] %M URI: '%{RURI}e' let_me_in: '%{let_me_in}e'"
[Thu Oct 22 14:27:29 2015] AH01626: authorization result of Require all granted: granted URI: '/hello/dostuff/foobar' let_me_in:
[Thu Oct 22 14:27:29 2015] AH01626: authorization result of <RequireAny>: granted URI: '/hello/dostuff/foobar' let_me_in:
[Thu Oct 22 14:27:29 2015] AH01626: authorization result of Require env let_me_in: denied URI: '/cgi-bin/hello.sh' let_me_in:
[Thu Oct 22 14:27:29 2015] AH01626: authorization result of <RequireAny>: denied URI: '/cgi-bin/hello.sh' let_me_in:
[Thu Oct 22 14:27:29 2015] AH01630: client denied by server configuration: /srv/http/cgi-bin/hello.sh URI: '/cgi-bin/hello.sh' let_me_in:
尝试添加:
SetEnvIf Request_URI "^/hello/dostuff/(.*)$" hello_params=$1
这个 var 肯定是在开始时设置的,但却RewriteRule
取消了它!
[Thu Oct 22 15:23:12 2015] AH01626: authorization result of Require all granted: granted URI: '/hello/dostuff/fooba' hello_params: 'fooba'
[Thu Oct 22 15:23:12 2015] AH01626: authorization result of <RequireAny>: granted URI: '/hello/dostuff/fooba' hello_params: 'fooba'
[Thu Oct 22 15:23:12 2015] AH01626: authorization result of Require env hello_params: denied URI: '/cgi-bin/hello.sh' hello_params:
[Thu Oct 22 15:23:12 2015] AH01626: authorization result of <RequireAny>: denied URI: '/cgi-bin/hello.sh' hello_params:
[Thu Oct 22 15:23:12 2015] AH01630: client denied by server configuration: /srv/http/cgi-bin/hello.sh URI: '/cgi-bin/hello.sh' hello_params:
答案1
RewriteRule
不会在下一轮取消设置自定义变量。它在其名称前面加上REDIRECT_
(至少在此处描述的情况下)https://stackoverflow.com/a/10128290/447503)。
因此只需改变一行就足够了:
Require env REDIRECT_let_me_in