Solved

PHP to stop Apache from logging specific 404s

Posted on 2009-05-07
3
522 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
Comment Utility
> 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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
This article discusses four methods for overlaying images in a container on a web page
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 …

763 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

9 Experts available now in Live!

Get 1:1 Help Now