RewriteCond with SetEnv

后端 未结 1 1948
被撕碎了的回忆
被撕碎了的回忆 2021-01-02 15:36

In my .htaccess I set:

SetEnv APPLICATION_ENV development

And I want to check if APPLICATION_ENV equals dev

相关标签:
1条回答
  • 2021-01-02 16:09

    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
    

    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]
    

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

    EDIT
    As julp pointed out in a comment to this post this is quite clear in Apache document section 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.
    
    0 讨论(0)
提交回复
热议问题