Solved

PHP to stop Apache from logging specific 404s

Posted on 2009-05-07
3
524 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

932 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now