Solved

PHP to stop Apache from logging specific 404s

Posted on 2009-05-07
3
534 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

737 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