本文介绍了与SETENV的RewriteCond的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的的.htaccess 我设置:

SetEnv APPLICATION_ENV development

和我想检查是否 APPLICATION_ENV 等于发展然后运行 app_dev.php ,否则 app.php

And I want to check if APPLICATION_ENV equals development then run app_dev.php, otherwise 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 脚本。我应该如何解决?

However it does not work - always runs app.php script. How should I fix it ?

推荐答案

由于我有这个测试自己,只能确认你写什么是正确的,我开始环顾四周,发现这个<一个href=\"http://turboflash.word$p$pss.com/2010/05/27/apache-environment-variables-visibility-with-setenv-setenvif-and-rewriterule-directives/\">post关于 SETENV SetEnvIf之后重写规则的知名度。它看起来像 SETENV 是不可见的的RewriteCond ,如果我改变你的例子是:

Since I had to test this myself and could only confirm that what you wrote was correct, I started to look around and found this post regarding SetEnv, SetEnvIf and RewriteRule visibility. It looks like SetEnv is not visible for RewriteCond and if I change your example to use:

SetEnvIf APPLICATION_ENV  ^(.*)$ APPLICATION_ENV=development

其实,我让你必须加载 app_dev.php 的规则。你可以通过设置变量重写规则以及

I actually get the rules you have to load app_dev.php. You could set the variable using RewriteRule as well:

RewriteRule .* - [E=APPLICATION_ENV:development,NE]

不过,看起来像 SETENV 不能使用(测试在Apache 2.2.22)。

However, looks like SetEnv can't be used (Tested on Apache 2.2.22).

修改结果
至于julp在这条信息的评论指出,这是Apache的文档部分设置环境变量

The SetEnv directive runs late during request processing meaning that directives
such as SetEnvIf and RewriteCond will not see the variables set with it.

这篇关于与SETENV的RewriteCond的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!