1

I have a Web Application.

All requests to my app will pass to Root/index.php. Example:

1. http://myapp.com/?call=phpfile1.processSomething&param1=x&param2=y
2. http://myapp.com/?call=phpfile2.processSomethingElse
3. http://myapp.com/?call=phpfile3.methodXYZ...

And I have an other app (WindowServices), it will call some Urls in my WebApp (All day :v). When I open access.log, It like this:

[2018-08-07 12:23:43] "GET /?call=phpfile1.processSomething&module=5 HTTP/1.1" 200 16
[2018-08-07 12:23:43] "GET /?call=phpfile2.processSomethingElse&module=2 HTTP/1.1" 200 16
[2018-08-07 12:23:43] "GET /?call=phpfile1.processSomething&module=0 HTTP/1.1" 200 16
[2018-08-07 12:23:43] "GET /?call=phpfile1.processSomething&module=7 HTTP/1.1" 200 16
[2018-08-07 12:23:43] "GET /?call=phpfile2.processSomethingElse&module=4 HTTP/1.1" 200 16
[2018-08-07 12:23:43] "GET /?call=phpfile2.processSomethingElse&module=3 HTTP/1.1" 200 16

And...access.log file will be large file over times.

So, I don't want Apache loging Urls:

1./?call=phpfile1.processSomething
2./?call=phpfile2.processSomethingElse

I seted some config in vhost file like this:

<VirtualHost *:80>
    DocumentRoot "D:\MyFolderApp"
   <Directory "D:\MyFolderApp">
         AllowOverride All
         Order allow,deny
         Allow from all
         DirectoryIndex index.php index.html
         Require all granted         
   </Directory>
   ServerName myapp.com
   SetEnvIf Request_URI "^/?call=phpfile1.processSomething" dontlog
   SetEnvIf Request_URI "^/?call=phpfile2.processSomethingElse" dontlog
   LogFormat "%h %l %u %t \"%r\" %>s %b" common
   CustomLog "logs/myapp.com-access.log" common env=!dontlog
</VirtualHost>

But Apache still write log for these Urls!!!

So, Any one help me!!! Thanks!

  • Your match strings in the `SetEnvIf` lines include some characters that need escaping: `?` -> `\?` and `.` -> `\.` If this doesn't work, try removing the `"` characters as well. – Nick Aug 07 '18 at 10:10
  • Thanks @Nick ! And I did do that. `SetEnvIf Request_URI "^/\?call=phpfile1\.processSomething" dontlog` But it doesn't work! – Trần Hưng Vượng Aug 07 '18 at 11:19
  • Have you tried printing out `Request_URI` to check it has the format/content you are matching? – Nick Aug 07 '18 at 11:22
  • I used this link to check: [link]https://regex101.com/[link] with RegEx: `^\/\?call=phpfile1\.processSomething`. Test string: `/?call=phpfile1.processSomething&module=5`. It's OK! – Trần Hưng Vượng Aug 07 '18 at 11:45
  • No, I meant what is the string you are matching against; i.e. print_r( Request_URI). If your regex is correct, then it must be your input. – Nick Aug 07 '18 at 11:56
  • `REQUEST_URI` doesn’t contain the `QUERY_STRING` only the path. The latter variable does, however. – Daniel Jun 11 '20 at 01:44

2 Answers2

1

Thanks to Nick and Tarun. I resolved my problem. In my .htaccess file, I add some configs:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^automate/phpfile1/(.*) ?call=phpfile1. processSomething&module=$1
    RewriteRule ^automate/phpfile2/(.*) ?call=phpfile2.processSomethingElse&module=$1
</IfModule>

And in my httpd-vhosts.conf file, I set like below:

SetEnvIf Request_URI "^/automate/phpfile1/"  dontlog
SetEnvIf Request_URI "^/automate/phpfile2/"  dontlog
CustomLog "logs/myapp.com-access.log" combined  env=!dontlog

So, apache doesn't logging Uris :D

0

Here in your configuration SetEnvIf Request_URI "^/?call=phpfile1.processSomething" dontlog, this line is in format

SetEnvIf attribute regex env-variable

So your regex is "^/?call=phpfile1.processSomething", in which there are special characters like '?'. Escape these characters and change your regex to something like ^\/\?call=phpfile1\.processSomething(.*).

Do remember to reload your apache configuration, reload or restart your apache server

Tarun Kumar
  • 201
  • 1
  • 4