Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP to stop Apache from logging specific 404s

Posted on 2009-05-07
3
Medium Priority
?
538 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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

610 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