RewriteCond with SetEnv

In mine, .htaccessI installed:

SetEnv APPLICATION_ENV development

And I want to check if APPLICATION_ENVequal development, then run app_dev.php, otherwiseapp.php

SetEnv APPLICATION_ENV development

RewriteCond %{ENV:APPLICATION_ENV} development
RewriteRule .? %{ENV:BASE}/app_dev.php [L]
RewriteRule .? %{ENV:BASE}/app.php [L]

However, it does not work - the app.phpscript is always executed . How to fix it?

+4
source share
1 answer

Since I had to check it myself and could only confirm that what you wrote was correct, I started looking around and found this post regarding SetEnv, SetEnvIfand RewriteRule. It SetEnvdoesn't seem to display for RewriteCondand if I use your example:

SetEnvIf APPLICATION_ENV  ^(.*)$ APPLICATION_ENV=development

, app_dev.php. RewriteRule:

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

, SetEnv ( Apache 2.2.22).


julp , :

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

All Articles