Bug 62936

Summary: Apache 2.4 does not exclude Request_Method from log using SetEnvIf regex
Product: Apache httpd-2 Reporter: Serge <altertag2013>
Component: mod_setenvifAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: RESOLVED INVALID    
Severity: normal    
Priority: P2    
Version: 2.5-HEAD   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description Serge 2018-11-21 15:15:36 UTC
Hello to Apache,

Environment
CentOS 7.5
Server version: Apache/2.4.6 (CentOS) installed from CentOS base repository using yum
LogFormat "%h %l %u %t \"%m %V%U %H\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
CustomLog /var/log/httpd/access_log combined env=!dontlog

Problem description
EXAMPLE 1 - OK 
SetEnvIf Request_URI "\.png$|\.gif$|\.jpg$|\.jpeg$|\.js$|\.css|\.woff$" dontlog
everything is ok, it excludes from Apache log the lines like 
83.266.84.27 - - [27/Oct/2018:14:07:19 -0500] "GET example.com/mod/maxtop.php HTTP/1.1" 200 3412 "http://example.com/image.png" "Mozilla/5.0 (Windows NT 10.0; rv:56.0) Gecko/20100101 Firefox/56.0"

EXAMPLE 2 - PROBLEM
SetEnvIf Request_Method "GET(.*)/maxtop\.php$" dontlog
does NOT exclude from Apache log the lines like
83.266.84.27 - - [27/Oct/2018:14:07:19 -0500] "GET example.com/mod/maxtop.php HTTP/1.1" 200 3412 "http://example.com/page218.html" "Mozilla/5.0 (Windows NT 10.0; rv:56.0) Gecko/20100101 Firefox/56.0"

I tried many other variations, for example
SetEnvIf Request_Method "\.php$" dontlog
but it does not work - anyway Apache does NOT exclude the according lines from log file.

I asked StackOverflow
https://stackoverflow.com/questions/53025708/apache-2-4-how-to-exclude-certain-get-requests-from-log-using-setenvif
but nobody can't answer there.

I did not find in Google no one REAL example how to do that.
A week ago I asked same from users@httpd.apache.org - but also nobody answered me.

Please, cross-check from your side - is this a bug of Apache 2.4 or mod_setenvif ?
Why 
SetEnvIf Request_URI "\.png$|\.gif$|\.jpg$|\.jpeg$|\.js$|\.css|\.woff$" dontlog - WORKS OK
but same
SetEnvIf Request_Method "\.php$" dontlog - DOES NOT WORK ?

Thanks in advance for attention and answer.
Comment 1 Eric Covener 2018-11-21 15:34:53 UTC
> Request_Method "GET(.*)/maxtop\.php$"

This will never match, Request_Method is something like "GET" alone.
Comment 2 Serge 2018-11-21 16:18:20 UTC
(In reply to Eric Covener from comment #1)
> > Request_Method "GET(.*)/maxtop\.php$"
> 
> This will never match, Request_Method is something like "GET" alone.

Do you mean we can only exclude ALL GET requests but not certain GET requests by regex like
SetEnvIf Request_Method "\.php$" dontlog
?
Please, comment precisely to understand the issue finally, otherwise the question should be REOPENED.
Comment 3 Eric Covener 2018-11-21 22:12:35 UTC
(In reply to Serge from comment #2)
> (In reply to Eric Covener from comment #1)
> > > Request_Method "GET(.*)/maxtop\.php$"
> > 
> > This will never match, Request_Method is something like "GET" alone.
> 
> Do you mean we can only exclude ALL GET requests but not certain GET
> requests by regex like
> SetEnvIf Request_Method "\.php$" dontlog
> ?
> Please, comment precisely to understand the issue finally, otherwise the
> question should be REOPENED.

You have to read the names of the parameters, Request_method has nothing to do with a URL.

The manual is pretty clear:
https://httpd.apache.org/docs/2.4/mod/mod_setenvif.html#setenvif
Request_Method - the name of the method being used (GET, POST, et cetera)

If you want to compare against the method and the URL at the same time, you'll have to use something more sophisticated like SetEnvIfExpr or <If>