I have a bit of an issue I was wondering if someone had an answer for.
I have a requirement to develop a custom 404 error handler to trap and handle 404 errors for CFM and CFC templates. That part is simple.
It also needs to still log the 404 error in the web server logs (Websphere/Apache) like it did before, for reporting purposes. That part is the sticking point.
First off, I found that setting a 404 error handler inside the CF admin will do one of two things, all based on what the error handler file does. In the first test case, the error handler logs the error in the CF logs, and then uses CFINCLUDE to display a styled error page. Because CF has now handled the file request with a fully working and existing template, it no longer tells the web server to log it as a 404 error. The web server now treats this as a 200 OK response.
Test case #2 is an error handler that logs the error, then uses CFLOCATION to send them to a safe place. Apache logs that as a 302 code for the redirect. It is interesting that CF can differentiate this, but there still is no way to alter this that I can determine.
I then took to setting up Apache's 404 error handling. I was able to get it to point to my CF 404 error handler template, which at first I thought would solve all the problems for non CFM/CFC templates. But then I found two major flaws in that.
Firstly all the Apache 404 error handler does is redirect the request to the error handler, again identifying it as a 302 status code instead of a 404.
The second issue is that it redirects the request so that CF has no way to get to the information regarding the file that was not found. When triggered through the CF admin 404 error handler, the error template has access to the CGI scope for the request to the missing file, which is how we properly log the request. Apache just does a redirect, leaving behind no CGI scope information that identifies the missing template. There is no HTTP_REFERER value, and the rest of the CGI scope refers to the error template itself, making it useless for us to use for logging.
And the Apache 404 error handler did NOT handle CFM or CFC files either. That surprised me.
So, I'm looking for any other options here to get it logged in the access_log file as a 404 while still handling and dealing with the error.