Do you want log only specific request and not all http requests?
It’s easy with apache module setenvif_module
Your options (terms) for logging are:
Remote_Host
Remote_Addr
Server_Addr
Request_Method
Request_Protocol
Request_URI
for example i have some requests like this:
http://linux-sysadmin.org/cms/show_article/8001.html?query=2
http://linux-sysadmin.org/cms/show_categories/6025_1.html?query=5
I want log request which contain word article and number 8001
in httpd.conf:
SetEnvIf Request_URI (article) my_request
SetEnvIf Request_URI (8001) my_request
CustomLog “|/opt/apache/bin/rotatelogs /var/web/log/httpd-test-access.log 3600″ \
“%h \”%r\” %t \”%{Referer}i\”" env=my_request
That’s is easy, but what must i do if i want log request by query string?
Unfortunately SetEnvIf can’t work for this problem, but you can use mod_rewrite module
and combine it with SetEnvIf.
Example of use (i want log request where query string is ‘query=2′ + previous terms):
in httpd.conf:
RewriteEngine On
SetEnvIf Request_URI (article) my_request
SetEnvIf Request_URI (8001) my_request
RewriteCond %{QUERY_STRING} (query=2)
RewriteRule (.*) $1 [E=my_request:yes]
CustomLog “|/opt/apache/bin/rotatelogs /var/web/log/httpd-test-access.log 3600″ \
“%h \”%r\” %t \”%{Referer}i\”" env=my_request
Easy?
I didn’t use special regexp. Of course, you can use very difficult regular (regexp) patterns
for find your specific request.
Tags: Apache Httpd, SetEnvIf, mod_rewrite, CustomLog, request