SetEnv in <Directory>

This is a discussion on SetEnv in <Directory> within the Apache Web Server forums, part of the Web Server and Related Forums category; Hello I have searched all over the place, but can't find an explanation for the following. I am trying ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-16-2008
markdibley@gmail.com
 
Posts: n/a
Default SetEnv in <Directory>

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.

<Directory "/cgi-bin/live/">
SetEnv USERSOURCE live
</Directory>
<Directory "/cgi-bin/test/">
SetEnv USERSOURCE test
</Directory>

However, I can only get the variable set if I use SetEnv OUTSIDE of
the <Directory> 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
  #2 (permalink)  
Old 01-16-2008
markdibley@gmail.com
 
Posts: n/a
Default Re: SetEnv in <Directory>

:-)

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

<Location "/cgi-bin/live/">
SetEnv USERSOURCE live
</Location >
<Location "/cgi-bin/test/">
SetEnv USERSOURCE test
</Location >

Thanks anyway

:-)
  #3 (permalink)  
Old 01-17-2008
sean dreilinger
 
Posts: n/a
Default Re: SetEnv in <Directory> (try setenvif too!)

markdibley@gmail.com wrote:
> Turns out it works if instead I use....
>
> <Location "/cgi-bin/live/">
> SetEnv USERSOURCE live
> </Location >
> <Location "/cgi-bin/test/">
> SetEnv USERSOURCE test
> </Location >


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

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/
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:51 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0