You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "West, Chris" <ch...@EDS.com> on 2007/05/21 12:55:18 UTC

[users@httpd] Comparing environmental variables in httpd.conf for conditional logic

I am trying to perform some conditional logic in my httpd.conf file
comparing two environment variables, the result of which will be used to
limit the logging in my referer logfile.  I have tried using both
SetEnvIf and RewriteCond to perform the logic in the following ways.

1:  Using SetEnvIf

    SetEnvIf Referer SERVER_NAME dont_log_ref
    CustomLog "|rotatelogs.exe logs/referer_log_iuk 86400" combined
env=!dont_log_ref

2.  Using Rewrite rules
    
     #
     # Set an env variable when we don't want to log the referer.
     #
    RewriteCond %{HTTP_REFERER} ^.*%{SERVER_NAME}.*$
    RewriteRule .* - [E=dont_log_referer:true]
    CustomLog "|rotatelogs.exe logs/referer_log_iuk 86400" combined
env=!dont_log_referer


For both methods, I have tried referencing SERVER_NAME variables as
above and also in form %{SERVER_NAME} and also %{ENV:SERVER_NAME}.  None
of these seem to work for the comparison however 

If I hardcode the comparison it works OK
i.e.

RewriteCond %{HTTP_REFERER} ^.*my_test_server.*$ 
RewriteRule .* - [E=dont_log_referer:true]
CustomLog "|rotatelogs.exe logs/referer_log_inter 86400" combined
env=!dont_log_referer

Any help would be much appreciated.

Chris West


Re: [users@httpd] Comparing environmental variables in httpd.conf for conditional logic

Posted by Joshua Slive <jo...@slive.ca>.
On 5/21/07, Neil A. Hillard <ne...@agustawestland.com> wrote:
> Hi,
>
> Joshua Slive wrote:

> > In any case, this isn't going to work. The regular expression used in
> > RewriteCond (and RewriteRule and SetEnvIf) cannot contain variables.
> > It is compiled at server-start and doesn't have access to anything
> > per-request.
> >
> > I don't think there is any way to do exactly what you want with
> > standard modules. You'll need to specify the ServerName explicitly in
> > the rules.
>
> I don't believe that's true.  I have the following rewrite to remove a
> prefix from the REMOTE_USER variable:
>
> RewriteCond        %{LA-U:REMOTE_USER} ^EXT_(.*)$
> RewriteRule        .* - [env=RU:%1]
>
> and:
>
> RewriteRule ^/$ http://%{SERVER_NAME}/site/ [R]
>
>
> I haven't got a spare server to play around with at the moment, but I'm
> sure something is possible.  Is it just a case of it doesn't like the
> environment variable on the RHS argument?
>
> As someone else asked, have you enabled the RewriteLog?

The regular expression part can't have a variable. In the RewriteCond
case, the regular expression is on the right, while in the RewriteRule
case it is on the left.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Comparing environmental variables in httpd.conf for conditional logic

Posted by "West, Chris" <ch...@eds.com>.
I was sure something was possible too, two days later I'm starting to
believe Joshua now.  The problem seems to be having the environment
variable in the regex side of the rewritecond statement.

Thanks for the reply

Chris West
Information Analyst
EDS - UKIMEA Commercial AIU
WoodHill House (2nd Floor)
Westburn Road
Aberdeen AB16 5GB
 
( Phone:+44 (0)1224 422517)
+ mailto:chris.west@eds.com

This email contains information which is confidential 
and may be privileged. Unless you are the intended 
addressee (or authorised to receive for the addressee) 
you may not use, forward, copy or disclose to anyone 
this email or any information contained in this email. If 
you have received this email in error, please advise 
the sender by reply email immediately and delete this email.

Electronic Data Systems Ltd
Registered Office:, Lansdowne House, Berkeley Square, London  W1J 6ER 
Registered in England no: 53419
VAT number: 432 99 5915

-----Original Message-----
From: Neil A. Hillard [mailto:neil.hillard@agustawestland.com] 
Sent: 21 May 2007 16:33
To: users@httpd.apache.org
Subject: Re: [users@httpd] Comparing environmental variables in
httpd.conf for conditional logic

Hi,

Joshua Slive wrote:
> On 5/21/07, Krist van Besien <kr...@gmail.com> wrote:
>> On 5/21/07, West, Chris <ch...@eds.com> wrote:
>> > Hi Krist,
>> >
>> > Sorry to get back to you again, I have tried the format you 
>> > described and still have problems, is the following how you would 
>> > expect the rewrite condition to look?  I have tried both, neither 
>> > giving the
>> result
>> > expected.
>> >
>> > 1.
>> >
>> >     RewriteCond %{HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
>> >     RewriteCond %{HTTP_REFERER} ^$
>> >     RewriteRule .* - [E=dont_log_referer:true]
>> >
>> > 2.
>> >
>> >     RewriteCond %{ENV:HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
>> >     RewriteCond %{ENV:HTTP_REFERER} ^$
>> >     RewriteRule .* - [E=dont_log_referer:true]
>>
>> After your other mail I know know that it is the "internal variable"
>> SERVER_NAME that you want to test against, and in this case 
>> %{SERVER_NAME} ought to be correct. %{HTTP_REFERER} is also correct.
>>
>> What could be your problem is that SERVER_NAME is not containing what

>> you expect, and that therefore the rule doesn't match. Have you tried

>> turning rewritelog on, and setting the loglevel to 9? This ought to 
>> give you a ton of information.
> 
> In any case, this isn't going to work. The regular expression used in 
> RewriteCond (and RewriteRule and SetEnvIf) cannot contain variables.
> It is compiled at server-start and doesn't have access to anything 
> per-request.
> 
> I don't think there is any way to do exactly what you want with 
> standard modules. You'll need to specify the ServerName explicitly in 
> the rules.

I don't believe that's true.  I have the following rewrite to remove a
prefix from the REMOTE_USER variable:

RewriteCond        %{LA-U:REMOTE_USER} ^EXT_(.*)$
RewriteRule        .* - [env=RU:%1]

and:

RewriteRule ^/$ http://%{SERVER_NAME}/site/ [R]


I haven't got a spare server to play around with at the moment, but I'm
sure something is possible.  Is it just a case of it doesn't like the
environment variable on the RHS argument?

As someone else asked, have you enabled the RewriteLog?


HTH,


				Neil.

-- 
Neil Hillard                    neil.hillard@agustawestland.com
AgustaWestland                  http://www.whl.co.uk/

Disclaimer: This message does not necessarily reflect the
            views of Westland Helicopters Ltd.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server
Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Comparing environmental variables in httpd.conf for conditional logic

Posted by "Neil A. Hillard" <ne...@agustawestland.com>.
Hi,

Joshua Slive wrote:
> On 5/21/07, Krist van Besien <kr...@gmail.com> wrote:
>> On 5/21/07, West, Chris <ch...@eds.com> wrote:
>> > Hi Krist,
>> >
>> > Sorry to get back to you again, I have tried the format you described
>> > and still have problems, is the following how you would expect the
>> > rewrite condition to look?  I have tried both, neither giving the
>> result
>> > expected.
>> >
>> > 1.
>> >
>> >     RewriteCond %{HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
>> >     RewriteCond %{HTTP_REFERER} ^$
>> >     RewriteRule .* - [E=dont_log_referer:true]
>> >
>> > 2.
>> >
>> >     RewriteCond %{ENV:HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
>> >     RewriteCond %{ENV:HTTP_REFERER} ^$
>> >     RewriteRule .* - [E=dont_log_referer:true]
>>
>> After your other mail I know know that it is the "internal variable"
>> SERVER_NAME that you want to test against, and in this case
>> %{SERVER_NAME} ought to be correct. %{HTTP_REFERER} is also correct.
>>
>> What could be your problem is that SERVER_NAME is not containing what
>> you expect, and that therefore the rule doesn't match. Have you tried
>> turning rewritelog on, and setting the loglevel to 9? This ought to
>> give you a ton of information.
> 
> In any case, this isn't going to work. The regular expression used in
> RewriteCond (and RewriteRule and SetEnvIf) cannot contain variables.
> It is compiled at server-start and doesn't have access to anything
> per-request.
> 
> I don't think there is any way to do exactly what you want with
> standard modules. You'll need to specify the ServerName explicitly in
> the rules.

I don't believe that's true.  I have the following rewrite to remove a
prefix from the REMOTE_USER variable:

RewriteCond        %{LA-U:REMOTE_USER} ^EXT_(.*)$
RewriteRule        .* - [env=RU:%1]

and:

RewriteRule ^/$ http://%{SERVER_NAME}/site/ [R]


I haven't got a spare server to play around with at the moment, but I'm
sure something is possible.  Is it just a case of it doesn't like the
environment variable on the RHS argument?

As someone else asked, have you enabled the RewriteLog?


HTH,


				Neil.

-- 
Neil Hillard                    neil.hillard@agustawestland.com
AgustaWestland                  http://www.whl.co.uk/

Disclaimer: This message does not necessarily reflect the
            views of Westland Helicopters Ltd.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Comparing environmental variables in httpd.conf for conditional logic

Posted by "West, Chris" <ch...@eds.com>.
Thanks Joshua,

After much banging of head on walls I was beginning to suspect that it
wasn't going to work.  I'll cut my losses now.

Regards

Chris West
Information Analyst
EDS - UKIMEA Commercial AIU
WoodHill House (2nd Floor)
Westburn Road
Aberdeen AB16 5GB
 
( Phone:+44 (0)1224 422517)
+ mailto:chris.west@eds.com

This email contains information which is confidential 
and may be privileged. Unless you are the intended 
addressee (or authorised to receive for the addressee) 
you may not use, forward, copy or disclose to anyone 
this email or any information contained in this email. If 
you have received this email in error, please advise 
the sender by reply email immediately and delete this email.

Electronic Data Systems Ltd
Registered Office:, Lansdowne House, Berkeley Square, London  W1J 6ER 
Registered in England no: 53419
VAT number: 432 99 5915

-----Original Message-----
From: jslive@gmail.com [mailto:jslive@gmail.com] On Behalf Of Joshua
Slive
Sent: 21 May 2007 16:14
To: users@httpd.apache.org
Subject: Re: [users@httpd] Comparing environmental variables in
httpd.conf for conditional logic

On 5/21/07, Krist van Besien <kr...@gmail.com> wrote:
> On 5/21/07, West, Chris <ch...@eds.com> wrote:
> > Hi Krist,
> >
> > Sorry to get back to you again, I have tried the format you 
> > described and still have problems, is the following how you would 
> > expect the rewrite condition to look?  I have tried both, neither 
> > giving the result expected.
> >
> > 1.
> >
> >     RewriteCond %{HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
> >     RewriteCond %{HTTP_REFERER} ^$
> >     RewriteRule .* - [E=dont_log_referer:true]
> >
> > 2.
> >
> >     RewriteCond %{ENV:HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
> >     RewriteCond %{ENV:HTTP_REFERER} ^$
> >     RewriteRule .* - [E=dont_log_referer:true]
>
> After your other mail I know know that it is the "internal variable"
> SERVER_NAME that you want to test against, and in this case 
> %{SERVER_NAME} ought to be correct. %{HTTP_REFERER} is also correct.
>
> What could be your problem is that SERVER_NAME is not containing what 
> you expect, and that therefore the rule doesn't match. Have you tried 
> turning rewritelog on, and setting the loglevel to 9? This ought to 
> give you a ton of information.

In any case, this isn't going to work. The regular expression used in
RewriteCond (and RewriteRule and SetEnvIf) cannot contain variables.
It is compiled at server-start and doesn't have access to anything
per-request.

I don't think there is any way to do exactly what you want with standard
modules. You'll need to specify the ServerName explicitly in the rules.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server
Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Comparing environmental variables in httpd.conf for conditional logic

Posted by Joshua Slive <jo...@slive.ca>.
On 5/21/07, Krist van Besien <kr...@gmail.com> wrote:
> On 5/21/07, West, Chris <ch...@eds.com> wrote:
> > Hi Krist,
> >
> > Sorry to get back to you again, I have tried the format you described
> > and still have problems, is the following how you would expect the
> > rewrite condition to look?  I have tried both, neither giving the result
> > expected.
> >
> > 1.
> >
> >     RewriteCond %{HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
> >     RewriteCond %{HTTP_REFERER} ^$
> >     RewriteRule .* - [E=dont_log_referer:true]
> >
> > 2.
> >
> >     RewriteCond %{ENV:HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
> >     RewriteCond %{ENV:HTTP_REFERER} ^$
> >     RewriteRule .* - [E=dont_log_referer:true]
>
> After your other mail I know know that it is the "internal variable"
> SERVER_NAME that you want to test against, and in this case
> %{SERVER_NAME} ought to be correct. %{HTTP_REFERER} is also correct.
>
> What could be your problem is that SERVER_NAME is not containing what
> you expect, and that therefore the rule doesn't match. Have you tried
> turning rewritelog on, and setting the loglevel to 9? This ought to
> give you a ton of information.

In any case, this isn't going to work. The regular expression used in
RewriteCond (and RewriteRule and SetEnvIf) cannot contain variables.
It is compiled at server-start and doesn't have access to anything
per-request.

I don't think there is any way to do exactly what you want with
standard modules. You'll need to specify the ServerName explicitly in
the rules.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Comparing environmental variables in httpd.conf for conditional logic

Posted by "West, Chris" <ch...@eds.com>.
Thanks Krist,

I will defintely do that and check it out.

regards

Chris West
Information Analyst
EDS - UKIMEA Commercial AIU
WoodHill House (2nd Floor)
Westburn Road
Aberdeen AB16 5GB
 
( Phone:+44 (0)1224 422517)
+ mailto:chris.west@eds.com

This email contains information which is confidential 
and may be privileged. Unless you are the intended 
addressee (or authorised to receive for the addressee) 
you may not use, forward, copy or disclose to anyone 
this email or any information contained in this email. If 
you have received this email in error, please advise 
the sender by reply email immediately and delete this email.

Electronic Data Systems Ltd
Registered Office:, Lansdowne House, Berkeley Square, London  W1J 6ER 
Registered in England no: 53419
VAT number: 432 99 5915

-----Original Message-----
From: Krist van Besien [mailto:krist.vanbesien@gmail.com] 
Sent: 21 May 2007 14:10
To: users@httpd.apache.org
Subject: Re: [users@httpd] Comparing environmental variables in
httpd.conf for conditional logic

On 5/21/07, West, Chris <ch...@eds.com> wrote:
> Hi Krist,
>
> Sorry to get back to you again, I have tried the format you described 
> and still have problems, is the following how you would expect the 
> rewrite condition to look?  I have tried both, neither giving the 
> result expected.
>
> 1.
>
>     RewriteCond %{HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
>     RewriteCond %{HTTP_REFERER} ^$
>     RewriteRule .* - [E=dont_log_referer:true]
>
> 2.
>
>     RewriteCond %{ENV:HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
>     RewriteCond %{ENV:HTTP_REFERER} ^$
>     RewriteRule .* - [E=dont_log_referer:true]

After your other mail I know know that it is the "internal variable"
SERVER_NAME that you want to test against, and in this case
%{SERVER_NAME} ought to be correct. %{HTTP_REFERER} is also correct.

What could be your problem is that SERVER_NAME is not containing what
you expect, and that therefore the rule doesn't match. Have you tried
turning rewritelog on, and setting the loglevel to 9? This ought to give
you a ton of information.

Krist


--
krist.vanbesien@gmail.com
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server
Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Comparing environmental variables in httpd.conf for conditional logic

Posted by Krist van Besien <kr...@gmail.com>.
On 5/21/07, West, Chris <ch...@eds.com> wrote:
> Hi Krist,
>
> Sorry to get back to you again, I have tried the format you described
> and still have problems, is the following how you would expect the
> rewrite condition to look?  I have tried both, neither giving the result
> expected.
>
> 1.
>
>     RewriteCond %{HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
>     RewriteCond %{HTTP_REFERER} ^$
>     RewriteRule .* - [E=dont_log_referer:true]
>
> 2.
>
>     RewriteCond %{ENV:HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
>     RewriteCond %{ENV:HTTP_REFERER} ^$
>     RewriteRule .* - [E=dont_log_referer:true]

After your other mail I know know that it is the "internal variable"
SERVER_NAME that you want to test against, and in this case
%{SERVER_NAME} ought to be correct. %{HTTP_REFERER} is also correct.

What could be your problem is that SERVER_NAME is not containing what
you expect, and that therefore the rule doesn't match. Have you tried
turning rewritelog on, and setting the loglevel to 9? This ought to
give you a ton of information.

Krist


-- 
krist.vanbesien@gmail.com
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Comparing environmental variables in httpd.conf for conditional logic

Posted by "West, Chris" <ch...@eds.com>.
Hi Krist,

Sorry to get back to you again, I have tried the format you described
and still have problems, is the following how you would expect the
rewrite condition to look?  I have tried both, neither giving the result
expected.

1.

    RewriteCond %{HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
    RewriteCond %{HTTP_REFERER} ^$
    RewriteRule .* - [E=dont_log_referer:true]

2.

    RewriteCond %{ENV:HTTP_REFERER} ^.*%{ENV:SERVER_NAME}.*$ [OR]
    RewriteCond %{ENV:HTTP_REFERER} ^$
    RewriteRule .* - [E=dont_log_referer:true]

Regards

Chris West
Information Analyst
EDS - UKIMEA Commercial AIU
WoodHill House (2nd Floor)
Westburn Road
Aberdeen AB16 5GB
 
( Phone:+44 (0)1224 422517)
+ mailto:chris.west@eds.com

This email contains information which is confidential 
and may be privileged. Unless you are the intended 
addressee (or authorised to receive for the addressee) 
you may not use, forward, copy or disclose to anyone 
this email or any information contained in this email. If 
you have received this email in error, please advise 
the sender by reply email immediately and delete this email.

Electronic Data Systems Ltd
Registered Office:, Lansdowne House, Berkeley Square, London  W1J 6ER 
Registered in England no: 53419
VAT number: 432 99 5915

-----Original Message-----
From: Krist van Besien [mailto:krist.vanbesien@gmail.com] 
Sent: 21 May 2007 12:46
To: users@httpd.apache.org
Subject: Re: [users@httpd] Comparing environmental variables in
httpd.conf for conditional logic

On 5/21/07, West, Chris <ch...@eds.com> wrote:
>
>
>
> I am trying to perform some conditional logic in my httpd.conf file 
> comparing two environment variables, the result of which will be used 
> to limit the logging in my referer logfile.  I have tried using both 
> SetEnvIf and RewriteCond to perform the logic in the following ways.
>
> 1:  Using SetEnvIf
>
>     SetEnvIf Referer SERVER_NAME dont_log_ref
>     CustomLog "|rotatelogs.exe logs/referer_log_iuk 86400" combined 
> env=!dont_log_ref
>
> 2.  Using Rewrite rules
>
>      #
>      # Set an env variable when we don't want to log the referer.
>      #
>     RewriteCond %{HTTP_REFERER} ^.*%{SERVER_NAME}.*$
>     RewriteRule .* - [E=dont_log_referer:true]
>     CustomLog "|rotatelogs.exe logs/referer_log_iuk 86400" combined 
> env=!dont_log_referer
>
>
> For both methods, I have tried referencing SERVER_NAME variables as 
> above and also in form %{SERVER_NAME} and also %{ENV:SERVER_NAME}.  
> None of these seem to work for the comparison however
>
> If I hardcode the comparison it works OK i.e.
>
> RewriteCond %{HTTP_REFERER} ^.*my_test_server.*$ RewriteRule .* - 
> [E=dont_log_referer:true] CustomLog "|rotatelogs.exe 
> logs/referer_log_inter 86400" combined env=!dont_log_referer
>
> Any help would be much appreciated.

Is the "SERVER_NAME" environment variable set in the shell that is used
to start Apache; or is it set elsewhere? In the context of an discussion
about apache "Environment variable" can mean two things, it is important
to know which meaning it has here.

Now, as far as I know you cannot use environment variables in the regex
part of a SetEnvIf statement. So your first solution will not work.

the second solution can work, but you need to refer to
%{ENV:SERVER_NAME} if you want an environment variable, and not a
mod_rewirte variabla.

Krist

--
krist.vanbesien@gmail.com
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server
Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Comparing environmental variables in httpd.conf for conditional logic

Posted by "West, Chris" <ch...@eds.com>.
Hi Krist,

The SERVER_NAME variable is a standard HTTP header environment variable
from the request we issue for the website.  Perhaps I was making a
mistake with the way that I was referencing the variable.  Thanks for
the reply, I can now definitely discount the SetEnvIf method at least,
and go back to try some more attempts with the rewritecond statement.

Regards

Chris West
Information Analyst
EDS - UKIMEA Commercial AIU
WoodHill House (2nd Floor)
Westburn Road
Aberdeen AB16 5GB
 
( Phone:+44 (0)1224 422517)
+ mailto:chris.west@eds.com

This email contains information which is confidential 
and may be privileged. Unless you are the intended 
addressee (or authorised to receive for the addressee) 
you may not use, forward, copy or disclose to anyone 
this email or any information contained in this email. If 
you have received this email in error, please advise 
the sender by reply email immediately and delete this email.

Electronic Data Systems Ltd
Registered Office:, Lansdowne House, Berkeley Square, London  W1J 6ER 
Registered in England no: 53419
VAT number: 432 99 5915

-----Original Message-----
From: Krist van Besien [mailto:krist.vanbesien@gmail.com] 
Sent: 21 May 2007 12:46
To: users@httpd.apache.org
Subject: Re: [users@httpd] Comparing environmental variables in
httpd.conf for conditional logic

On 5/21/07, West, Chris <ch...@eds.com> wrote:
>
>
>
> I am trying to perform some conditional logic in my httpd.conf file 
> comparing two environment variables, the result of which will be used 
> to limit the logging in my referer logfile.  I have tried using both 
> SetEnvIf and RewriteCond to perform the logic in the following ways.
>
> 1:  Using SetEnvIf
>
>     SetEnvIf Referer SERVER_NAME dont_log_ref
>     CustomLog "|rotatelogs.exe logs/referer_log_iuk 86400" combined 
> env=!dont_log_ref
>
> 2.  Using Rewrite rules
>
>      #
>      # Set an env variable when we don't want to log the referer.
>      #
>     RewriteCond %{HTTP_REFERER} ^.*%{SERVER_NAME}.*$
>     RewriteRule .* - [E=dont_log_referer:true]
>     CustomLog "|rotatelogs.exe logs/referer_log_iuk 86400" combined 
> env=!dont_log_referer
>
>
> For both methods, I have tried referencing SERVER_NAME variables as 
> above and also in form %{SERVER_NAME} and also %{ENV:SERVER_NAME}.  
> None of these seem to work for the comparison however
>
> If I hardcode the comparison it works OK i.e.
>
> RewriteCond %{HTTP_REFERER} ^.*my_test_server.*$ RewriteRule .* - 
> [E=dont_log_referer:true] CustomLog "|rotatelogs.exe 
> logs/referer_log_inter 86400" combined env=!dont_log_referer
>
> Any help would be much appreciated.

Is the "SERVER_NAME" environment variable set in the shell that is used
to start Apache; or is it set elsewhere? In the context of an discussion
about apache "Environment variable" can mean two things, it is important
to know which meaning it has here.

Now, as far as I know you cannot use environment variables in the regex
part of a SetEnvIf statement. So your first solution will not work.

the second solution can work, but you need to refer to
%{ENV:SERVER_NAME} if you want an environment variable, and not a
mod_rewirte variabla.

Krist

--
krist.vanbesien@gmail.com
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server
Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Comparing environmental variables in httpd.conf for conditional logic

Posted by Krist van Besien <kr...@gmail.com>.
On 5/21/07, West, Chris <ch...@eds.com> wrote:
>
>
>
> I am trying to perform some conditional logic in my httpd.conf file
> comparing two environment variables, the result of which will be used to
> limit the logging in my referer logfile.  I have tried using both SetEnvIf
> and RewriteCond to perform the logic in the following ways.
>
> 1:  Using SetEnvIf
>
>     SetEnvIf Referer SERVER_NAME dont_log_ref
>     CustomLog "|rotatelogs.exe logs/referer_log_iuk 86400" combined
> env=!dont_log_ref
>
> 2.  Using Rewrite rules
>
>      #
>      # Set an env variable when we don't want to log the referer.
>      #
>     RewriteCond %{HTTP_REFERER} ^.*%{SERVER_NAME}.*$
>     RewriteRule .* - [E=dont_log_referer:true]
>     CustomLog "|rotatelogs.exe logs/referer_log_iuk 86400" combined
> env=!dont_log_referer
>
>
> For both methods, I have tried referencing SERVER_NAME variables as above
> and also in form %{SERVER_NAME} and also %{ENV:SERVER_NAME}.  None of these
> seem to work for the comparison however
>
> If I hardcode the comparison it works OK
> i.e.
>
> RewriteCond %{HTTP_REFERER} ^.*my_test_server.*$
> RewriteRule .* - [E=dont_log_referer:true]
> CustomLog "|rotatelogs.exe logs/referer_log_inter 86400" combined
> env=!dont_log_referer
>
> Any help would be much appreciated.

Is the "SERVER_NAME" environment variable set in the shell that is
used to start Apache; or is it set elsewhere? In the context of an
discussion about apache "Environment variable" can mean two things, it
is important to know which meaning it has here.

Now, as far as I know you cannot use environment variables in the
regex part of a SetEnvIf statement. So your first solution will not
work.

the second solution can work, but you need to refer to
%{ENV:SERVER_NAME} if you want an environment variable, and not a
mod_rewirte variabla.

Krist

-- 
krist.vanbesien@gmail.com
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org