When I try to access a page that is not found, Coldfusion 10 provides this error page instead of redirecting to our 404 Page Not Found page. How can I get Coldfusion to redirect to our Page Not Found page instead of providing this error message?
-
2Have you set the missing template handler in CFAdmin? – Adam Cameron Aug 27 '13 at 16:18
-
1Or setup onMissingTemplate function in Application.cfc (if so, post the code) – Peter Boughton Aug 27 '13 at 16:34
2 Answers
At he point at which the error is thrown the web server is not actually in control of the request. It is waiting for CF to "hand back" the request as string buffer - content to serve.
That means there is an additional step in CF to handle missing templates. You can set (as Adam has said) the missing template handler in the CF admin - or if you are using an Application.cfc you can use the function onMissingTemplate() to do whatever you think is appropriate for a missing cfm page.

- 34,448
- 50
- 182
- 322

- 7,183
- 20
- 21
-
We can add a page to the "Missing Template Handler" in the Coldfusion Administrator, but it doesn't seem to accept a Coldfusion page as the Page Not Found page (ours is /errorPages/404.cfm). It will, however, allow us to use a plain txt file or plain HTML file. How come it won't process the CFM file as the Page Not Found page? – azam Aug 27 '13 at 20:07
-
@azam - it will indeed accept a ColdFusion page as the missing template handler. Your issue is most likely that it cannot find your ColdFusion page at `/errorPages/404.cfm`. The ColdFusion page must be under your webroot and the reference to it under the Missing Template Handler is relative to the webroot. – Miguel-F Aug 27 '13 at 20:46
-
@Miguel-F - Okay, upon further investigation, it's finding our 404.cfm page, but it is losing our application scope among other things. It can process the cfm but our `/errorpages/404.cfm` has references to application scope, and I believe it's triggering an error. How come these scopes are lost when the 'Missing Template Handler' is triggered? – azam Aug 27 '13 at 21:04
-
@azam - I believe I worded my previous comment incorrectly so I have updated it here. If your application variables are not available you can always call the `onApplicationStart` method from your 404 page. – Miguel-F Aug 28 '13 at 12:13
-
@Al - your application.cfc will need to be "in the path" of the 404 handler for it to load the application vars. I'm not sure calling on application start is going to work in this instance unless you are "inside" the application. But you can extend your site application using a different application.cfc or you can "include" the other application.cfm page at the top of your 404 handler. – Mark A Kruger Aug 28 '13 at 13:57
Since the request was made for a .cfm page Coldfusion is expected to handle the request, since the file is not found then Coldfusion triggers the standard 404 error. You can do 1 of 2 things:
- Set up a 404 template on the Coldfusion administrator, as Mark A Kruger suggested.
- Set up the Application.cfc to handle the request by using the onMissingTemplate() function. Here is more documentation on that: http://bit.ly/17k4Ry8
NOTE: You can set up your onMissingTemplate() function to redirect to the actual 404 template, since it sounds like you already have one. This would be considered a Soft 404 to the crawlers.
Good Luck!
Thanks -Al

- 1