Solved

PHP to stop Apache from logging specific 404s

Posted on 2009-05-07
3
527 Views
Last Modified: 2013-12-13
[Thu May  7 13:23:47 2009] [error] [client xx.xx.xxx.x] File does not exist: /home/osbornew/live/7150.cfm

The trick is, I've got a custom 404 error handling page.  It queries a database with the info /7150.cfm and serves up a valid page.  If /7150.cfm is not in the database, it shows the 404 error page and gives the 404 header.

The trouble is all of these "File does not exist" messages are filling up my Apache error log.  Can I disable them with PHP if it finds something in the DB?  And/or, can we disable logging 404 messages altogether for Apache?

Thanks!
0
Comment
Question by:M256
  • 2
3 Comments
 
LVL 27

Expert Comment

by:caterham_www
ID: 24334772
> Can I disable them with PHP if it finds something in the DB?

If you use mod_php (i.e. no cgi/fastcgi solution). yes.

php:
apache_setenv('dontlog', '1');

and in your apache configuration
You should find a line starting with

CustomLog logs/access_log combined
(or similar). Change it to
CustomLog logs/access_log combined env=!dontlog


> And/or, can we disable logging 404 messages altogether for Apache?

No, only with a (simple) self-written solution (c module, mod_perl) since you can't set an env after the handler runs with the directives provided by apache.
0
 
LVL 5

Author Comment

by:M256
ID: 24435101
I implemented your solution, yet still see the error messages in my log.

To confirm, I put this in my dnserror script:
apache_setenv('dontlog', '1');

In my logs I changed the applicable CustomLog to this:
CustomLog "logs/access.log" common env=!dontlog
0
 
LVL 5

Accepted Solution

by:
M256 earned 0 total points
ID: 24732071
I am looking in to using mod rewrite to solve this problem:
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Apache/Q_24468345.html
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question