htaccess If…Else always selects Else

前端 未结 4 1796
温柔的废话
温柔的废话 2021-02-12 21:59

I set an environment variable in httpd-vhosts.conf

SetEnv EARLY_VAR 1

I try setting special rules based on its value in

4条回答
  •  广开言路
    2021-02-12 22:49

    Looking at the documentation of SetEnv directive, I notice:

    Sets an internal environment variable, which is then available to Apache HTTP Server modules, and passed on to CGI scripts and SSI pages.

    which means that the environments are then available to other modules. Whereas, directive is provided by the core. This can be confirmed if you try to see whether the environment is empty during the clause:

    
       SetEnv TEST_VAR  if_branch
    
    

    or

    
       SetEnv TEST_VAR  if_branch
    
    

    both will give you:

    string(1) "1" string(9) "if_branch" 
    

    in your PHP.


    There is also the following caveat listed on the Apache's environment variables wiki/docs pages:

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

提交回复
热议问题