在我的.htaccess中我设置了:
SetEnv APPLICATION_ENV development我想检查APPLICATION_ENV是否等于development,然后运行app_dev.php,否则为app.php
SetEnv APPLICATION_ENV development
RewriteCond %{ENV:APPLICATION_ENV} development
RewriteRule .? %{ENV:BASE}/app_dev.php [L]
RewriteRule .? %{ENV:BASE}/app.php [L]但是,它不起作用-始终运行app.php脚本。我该怎么解决它呢?
发布于 2013-10-14 23:10:50
因为我必须自己测试,只能确认你写的是正确的,所以我开始四处寻找,找到了这个关于SetEnv,SetEnvIf和RewriteRule可见性的post。看起来SetEnv对于RewriteCond是不可见的,如果我将您的示例更改为使用:
SetEnvIf APPLICATION_ENV ^(.*)$ APPLICATION_ENV=development实际上,我知道加载app_dev.php的规则。您也可以使用RewriteRule设置该变量:
RewriteRule .* - [E=APPLICATION_ENV:development,NE]但是,看起来SetEnv不能使用(在Apache2.2.22上测试)。
编辑
正如julp在对这篇文章的评论中指出的那样,这一点在Apache document部分Setting Environment Variables中已经很清楚了。
The SetEnv directive runs late during request processing meaning that directives
such as SetEnvIf and RewriteCond will not see the variables set with it.https://stackoverflow.com/questions/19362746
复制相似问题