Jump to content

How to not log image requests from local pages

0
  Rich Bowen's Photo
Posted Sep 01 2009 08:23 AM

If you want to log requests for images on your site, but not requests from your own pages, use SetEnvIfNoCase to restrict logging to only those requests from outside of your site:



    SetEnvIfNoCase Referer "^http://www.example.com/" local_referrer=1



CustomLog logs/access_log combined env=!local_referrer

In many cases, documents on a Web server include references to images also kept on the server, but the only item of real interest for log analysis is the referencing page itself. How can you keep the server from logging all the requests for the images that happen when such a local page is accessed?

The SetEnvIfNoCase will set an environment variable if the page that linked to the image is from the www.example.com site (obviously, you should replace that site name with your own) and the request is for a GIF, PNG, or JPEG image.

Tip

SetEnvIfNoCase is the same as SetEnvIf except that variable comparisons are done in a case-insensitive manner.

The CustomLog directive will log all requests that do not have that environment variable set, i.e., everything except requests for images that come from links on your own pages.

This recipe only works for clients that actually report the referring page. Some people regard the URL of the referring page to be no business of anyone but themselves, and some clients permit the user to select whether to include this information or not. There are also “anonymizing” sites on the Internet that act as proxies and conceal this information.

Cover of Apache Cookbook
Learn more about this topic from Apache Cookbook, 2nd Edition. 

The new edition of the Apache Cookbook offers you updated solutions to the problems you're likely to encounter with Apache. Thoroughly updated for Apache versions 2.0 and 2.2, this book includes more than 200 recipes ranging from simple tasks, such installing the server on Red Hat Linux or Windows, to more complex tasks, such as setting up name-based virtual hosts or securing and managing your proxy server.

Learn More Read Now on Safari


Tags:
0 Subscribe


0 Replies