Search code examples
phpapachevhostssetenvif

How to make Apache stop log some my Urls


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!


Solution

  • 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