Re: Comparing environmental variables in httpd.conf for conditional logic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/21/07, West, Chris <chris.west@xxxxxxx> 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@xxxxxxxxx
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@xxxxxxxxxxxxxxxx
  "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux