We have a server setup as follows:
Use the Application.cfc OnMissingTemplate method to handle a missing template page.
In Application.cfc add this
<cffunction name="onMissingTemplate">
<cfargument name="targetPage" type="string" required=true/>
<!--- No standard error handling here so we need to try/catch --->
<cftry>
<!--- Can't do a redirect so we'll do an "include" --->
<cfset missingPage=Arguments.targetPage>
<cfinclude template="/errors/404.cfm">
<cfcatch>
<!--- Let the standard missing file (404) process occur --->
<cfreturn false />
</cfcatch>
</cftry>
</cffunction>
In /errors/404.cfm add this near the top
<cfparam name="missingPage" type="string" default="">
<cfif missingPage eq "">
<!--- Include CGI variable and process as fitting for your purposes --->
<cfset missingPage=CGI.QUERY_STRING>
</cfif>
Let me preface my answer by stating that I am still running ColdFusion 9 so I don't have first-hand experience with the 404 handling in ColdFusion 10 with Tomcat. Obviously I will need to upgrade to version 10 so I am trying to familiarize myself with it's nuances (like handling 404's). So I did some searching.
As you stated in your question, with ColdFusion 9 and IIS the originally requested file is normally contained with the CGI.QUERY_STRING
variable prepended with "404;". With ColdFusion 10 and Tomcat it appears as though some other CGI
variables contain the originally requested file and it depends on your setup which variable that is.
I found this blog post by Raymond Camden - Reminder--there-is-more-to-the-CGI-scope-than-what-the-dump-shows. While that contains good info in itself I also found within the comments by Jules Gravinese the following:
When using IIS7 the variable is CGI.HTTP_X_ORIGINAL_URL
When using ISAPI_rewrite the variable is CGI.HTTP_X_REWRITE_URL
When using APACHE the variable is CGI.REDIRECT_URL
I also found some other articles referencing a CGI.REDIRECT_QUERY_STRING
variable which I believe is also included when using APACHE.
Found another article from Adobe regarding the CGI variables and how they are used with ColdFusion (and how/why it is not a complete list): CGI environment (CGI Scope) variables.
NOTE: I also found this bug ColdFusion 10.0 - Bug 3488063: IIS 404 custom error handler URLs that are .cfm files do not consistently return entire document which has been closed but several recent comments suggest that it is still an issue. So be aware of that.
NOTE: Question above includes a solution as well.
I think this is an error with the Coldfusion Connector. I would post a bug report to Adobe (https://bugbase.adobe.com/). I do have a workaround though. I have the same issue, but I use IIRF (Ionic IIS Redirector - http://iirf.codeplex.com/), and I found a way to use that to avoid the bug for now:
In the IirfGlobal.ini file (normally located in C:\Windows\System32\inetsrv\IIRF), add the following line:
RewriteFilterPriority HIGH
This will allow IIRF to handle 404 requests before it even hits ColdFusion/Tomcat.
In the site-specific Iirf.ini (usually you create one in the root folder of your web files -- see the IIRF docs for details), add the following rules:
RewriteCond %{SCRIPT_TRANSLATED} !-f
RewriteCond %{SCRIPT_TRANSLATED} !-d
RewriteRule ^(.+)$ page_to_redirect_to.cfm?404;$1 [L]
That will redirect all files/directories that don't exist to page_to_redirect_to.cfm, and add the 404 query string like normal.
EDIT: Added a following step: Go into the IIS Manager and select either the server or the Web Site that was configured to use IIRF, then go into the ISAPI Filters section. Click on "View Ordered List", then move the IIRF filter up to the top.
EDIT 2: Just posted a bug to Adobe. See https://bugbase.adobe.com/index.cfm?event=bug&id=3630245
Hope that helps.