问题描述
是否仍然可以使用RewriteRule
语句的SetEnv
中设置的值?
Is there anyway to use the value set in a SetEnv
on the RewriteRule
statement?
示例:
SetEnv MY_SCRIPT myScript.php
rewriteEngine on
RewriteRule ^(.*)$ %{MY_SCRIPT} [L]
推荐答案
根据 http: //httpd.apache.org/docs/2.0/env.html 在RewriteRule之后的之后,SetEnv被称为.因此,似乎不可能在RewriteRule或RewriteCond语句中使用通过SetEnv设置的任何变量.
According to http://httpd.apache.org/docs/2.0/env.html the SetEnv is called after the RewriteRule. Therefore it seems to be impossible to use any variable set via SetEnv in a RewriteRule- or RewriteCond-statement.
另一方面,在RewriteRule之前,使用SetEnvIf被称为之前,因此在RewriteRule或RewriteCond语句中可以使用在那里设置的变量.
Using SetEnvIf on the other hand is called before the RewriteRule and therefore Variables set there can be used in a RewriteRule- or RewriteCond-statement.
所以类似以下的内容应该起作用:
So something like the following should work:
SetEnvIf SERVER_PROTOCOL "HTTP.*" MY_SCRIPT=myScript.php
rewriteEngine on
RewriteRule ^(.*)$ %{ENV:MY_SCRIPT} [L]
这篇关于mod_rewrite规则和setenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!