Apache: Environment Variables Visibility with SetEnv, SetEnvIf and RewriteRule Directives

This blog has moved. Please click here.

10 Comments »

  1. Steven said

    Wow, thanks for this! I was trying to do some advanced variable setting and rewriting and this was extremely useful.

  2. Vector said

    Hey, i feel your pain on this one. I was about to shoot someone until i finally got this working. And you’re right: there’s NO fcking docs on how to PROPERLY do this. So it’s trial and error, and time wasted.

    Anyway, i DID find a working example, while trying to setup apache to handle mobile redirects for TheSocialExpo.com and i posted an article about it here:

    http://thesocialexpo.com/?a=WCMS_Article_Display&id=13001842310325634&page=1

    I came across you while i was trying to solve this problem, so i figured i’d come back and share my findings as well.

    • turboflash said

      Thanks for the information. :)

    • Do you have a copy of that page? It is offline now :( Would like to find a fix for this…

  3. Christian said

    Thanks for this! very useful, exactly what I was looking for.

  4. This was wonderfully useful. It saved me hours. Thanks so much. I’ve brought it to the webfaction community here: http://community.webfaction.com/questions/8694/using-rewritecond-to-simulate-rewritebase-for-hosting-same-app-at-root-and-subdirectory

  5. Alex said

    May be I didn’t get something, but official documentation IMHO clearly explain it.

    http://httpd.apache.org/docs/2.2/mod/core.html#ifdefine
    “Encloses directives that will be processed only if a test is true >>>at startup<<>>after<<>>If the environment variable you’re setting is meant as input into this early phase of processing such as the RewriteRule directive, you should instead set the environment variable with SetEnvIf.<<<"

  6. Alex said

    May be I didn’t get something, but official documentation IMHO clearly explain it.

    http://httpd.apache.org/docs/2.2/mod/core.html#ifdefine
    “Encloses directives that will be processed only if a test is true +++at startup+++”
    It means any existing system env.vars will be available for IFDefine.
    One more way to pass environment variable on start to Apache only instead of setting it system wide it is place file(s) to directory
    etc/apache22/envvars.d in the same way as it done in standard Burne shell


    #-------------- comments about var ....
    MySpecialSuperDuperIP='11\.22\.33\.44'
    export MySpecialSuperDuperIP
    #=========================

    that “MySpecialSuperDuperIP” will be available later for all tests

    As of “setenv”:

    http://httpd.apache.org/docs/2.2/mod/mod_env.html#setenv
    “The internal environment variables set by this directive are set +++after+++ most early request processing directives are run, such as access control and URI-to-filename mapping. +++If the environment variable you’re setting is meant as input into this early phase of processing such as the RewriteRule directive, you should instead set the environment variable with SetEnvIf.+++”

    P.S.
    Sorry for previous post, forget that wordpress don’t like some characters

  7. […] 首先想到的是通过访问控制模块mod_authz_host的Deny from env来实现。Deny from能够访问的只有SetEnvIf设置的环境变量。有个老外做了个有趣的实验汇总了Apache 2.2下环境变量相关的各个指令(SetEnv/SetEnvIf/RewriteRule/Header/RewriteCond/IfDefine/Allow/Deny)设置/访问的作用范围,有兴趣的可以看看,需要翻墙,Apache: Environment Variables Visibility with SetEnv, SetEnvIf and RewriteRule Directives,翻不了墙的可以直接看这张表。 […]

  8. Cosimo said

    Great post. Thanks for it.

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: