SetEnv in <Directory>

SetEnv in <Directory>

am 16.01.2008 13:01:07 von markdibley

Hello

I have searched all over the place, but can't find an explanation for
the following.

I am trying to set different environment variables depending on what
what directory the accessed cgi script is in.

/var/www/cgi-bin/live/report.cgi
/var/www/cgi-bin/test/report.cgi

where report.cgi simply is

print $ENV{'USERSOURCE'}

I thought by adding the following to my httpd.conf file and stopping
and then starting /etc/init.d/httpd the scripts would give me
different outputs.


SetEnv USERSOURCE live


SetEnv USERSOURCE test


However, I can only get the variable set if I use SetEnv OUTSIDE of
the tags (and is therefore global). I have run httpd -t to
check the syntax and all that works. Can anyone tell me why you cannot
set specific environment variables based on the directory directive?

Thanks for your help and attention

Mark

Re: SetEnv in <Directory>

am 16.01.2008 13:24:55 von markdibley

:-)

Turns out it works if instead I use....


SetEnv USERSOURCE live


SetEnv USERSOURCE test


Thanks anyway

:-)

Re: SetEnv in <Directory> (try setenvif too!)

am 17.01.2008 19:01:33 von sean dreilinger

markdibley@gmail.com wrote:
> Turns out it works if instead I use....
>
>
> SetEnv USERSOURCE live
>

>
> SetEnv USERSOURCE test
>


based on this excerpt from the setenvif directive documentation:
http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html#seten vif

Since version 2.0.51 Apache will recognize occurrences of $1..$9 within
value and replace them by parenthesized subexpressions of regex.

you could probably avoid the hassle of the pre-arranging every possible
"usersource" into a location stanza, and just use a single line like this to
cover all cases:

SetEnvIf Request_URI "/cgi-bin/(.*?)/" USERSOURCE=$1

hth
--sean

--
sean dreilinger - http://durak.org/sean/