Forum Moderators: phranque

Message Too Old, No Replies

SetEnvIf working (?)

problems with SetEnvIf configuration

         

supervazi

7:11 am on Oct 21, 2010 (gmt 0)

10+ Year Member



Hi all,

I need some kind of ID in the apache log associated with some URIs. Something like this:

/some/uri1/............some1
/some/uri2/............some2
.
.
.
/other/uri/.............. -

So I tried to resolve this problem with SetEnvIf:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{__utma}C\" \"%{id}e\"" combined_2
SetEnvIf Request_URI "/some/uri1/" id=some1
SetEnvIf Request_URI "/some/uri2/" id=some2
CustomLog access_log combined_2

The problem is, there is always the "-" in the log...

It is something wrong with this solution? Or the .conf part is buggy?

Thank you in advance.

vazi

supervazi

9:29 am on Oct 21, 2010 (gmt 0)

10+ Year Member



SetEnvIf not working but resolved with other solution:


RewriteRule ^some/uri(1-9)/$ [CO=__s:s$1:domain]

and

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
\"%{User-Agent}i\" \"%{__utma}C\" \"%{__s}C\"" combined_2

Thank you,

jdMorgan

12:59 pm on Oct 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your SetEnvIf line
 SetEnvIf Request_URI "^/some/uri[1-9]/" id=some1 

should have worked, unless "Options FileInfo" is not set in the server config. Enclosing this directives inside a <Files> or <FileMatch> container could also cause trouble, since these sections are processed later than the rest of your configuration directives (See "How the sections are merged" at [httpd.apache.org...]

Using a cookie introduces a client dependency -- your code won't work if the client (a browser or robot, for example) does not accept cookies. So I'm wondering if you also tried

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{__utma}C\" \"%{URI_id}e\"" combined_2
#
RewriteRule ^some/uri[1-9]/$ - [E=URI_id:some1]

to set "URI_id" variable for logging. (I used a longer variable name just in case "id" is used for some other purpose. Using longer names reduces the chances of such "naming collisions.")

Note the changes to the regular-expressions and RewriteRule syntax -- "[1-9]" to match "any single character from one to nine" and the use of "-" to indicate "no change to requested URL-path."

Jim

supervazi

7:11 am on Oct 22, 2010 (gmt 0)

10+ Year Member



Thanks

[edited by: supervazi at 7:13 am (utc) on Oct 22, 2010]

supervazi

7:11 am on Oct 22, 2010 (gmt 0)

10+ Year Member



Thank you for response.

I don't have "Options FileInfo" set. I also tried RewriteRule scenario with variable first, same negative result. Then came this idea with cookie (of course with "[" and not "(" ).