Forum Moderators: phranque
Welcome to WebmasterWorld [webmasterworld.com]!
> ...is there any way to prevent the 404 errors being recorded in apache's log...?
I don't think so...
You might better off changing your script to modify the server status response header according to the results of your database lookup.
ErrorDocument is only meant to handle simple static-site error responses, and doesn't work well for much beyond that. In many cases, even if ErrorDocument can be forced to do something "special", the result is confused search engine spiders and dropped sites. This is especially true when *all* missing pages are redirected to the home page or to a script that always returns a 200-OK.
I'm not a php guru, but I've seen code posted in our php forum that has to do with setting server response headers, and that's what I'd use for your described problem.
Jim
Don't use ErrorDocument at all - just redirect unconditionally to your script using mod_rewrite or one of the "ScriptAlias" directives. Inside the script, write the appropriate 200 or 404 response.
Jim
<edit> To clarify: ErrorDocument is processed before your script is called. And the reponse code is written by the server before ErrorDocument is called. Once the server writes the response header, no subsequent agent can modify that response in the logs. The mod_alias and mod_rewrite modules are processed before the "file exists" check is done by the server, which gives your script a chance to write to the blank server response variable.</edit>
RewriteEngine on
RewriteCond %{REQUEST_URI}!^/includes/404.php
RewriteRule ^(.*)$ /includes/404.php?$1
Thanks to jdMorgan in the "RewriteRule in .htaccess file" thread for helping me to figure this out!