Ask a Jedi: onMissingTemplate in ColdFusion 7?

This post is more than 2 years old.

Craig asks:

Do you know how to handle MissingTemplate errors on the application level in CF7. I know CF8 has a new application function onMissingTemplate() that handles this but am having difficulties with this in CF7.

So Craig is right - this support is something that was added to ColdFusion 8, not 7. You can certainly add it to your Application.cfc but it won't fire automatically. (Folks, don't forget that Application.cfc can include additional methods!)

In ColdFusion 7, the only option you have similar is the Missing Template handler in the ColdFusion Administrator:

This is server wide, and unlike onMissingTemplate, you can't do processing before the file itself is loaded. So for example, if you want to say that any missing template with "store" in the URL should point to, you would need to put that logic within your CFM.

You do have access to the requested template information - but not via an explicit passed in arguments but rather the CGI scope instead.

So - it isn't quite as nice as onMissingTemplate, but it's something. I'm convinced that simply ignoring 404 requests is one of the biggest mistakes you can make on a web site (and I admit to this as well!).

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Craig Heneveld posted on 6/25/2009 at 6:26 PM

Thanks for the tip Ray. I was curious if you know where the coldfusion default onMissingTemplate template is located? Is this in the cf file system, or is this compiled at runtime? I would like to base my custom template from this.

Comment 2 by Raymond Camden posted on 6/25/2009 at 6:37 PM

There is a default response, but no default file you can edit. So if you want to modify the default you would need to make a 100% new file.

Comment 3 by Steve Gongage posted on 6/26/2009 at 3:15 PM

"I'm convinced that simply ignoring 404 requests is one of the biggest mistakes you can make on a web site"

Hey Ray, just wondering if you would ellaborate a little more on what you said here. The reason being, I'm playing around with using "onMissingTemplate" to help me spoof search engine safe urls under IIS and I want to see if I'm making a mistake before going to far.

In my example when someone enters in:

The onMissingTemplate method of Application.cfc will fire (since there will not be either a storefront directory or a lightsabers.cfm template). Lets say we parse the requesting URL in the onMissingTemplate method, figure out we're really going to:

So, technically, if someone punches in anything with a .cfm extension they should technically never get a 404 error in my app. At worst they will be redirected to the root of the site or perhaps the root of the storefront module.

Comment 4 by Gary Gilbert posted on 6/26/2009 at 4:30 PM


If I were you I would still provide a means of catching a non-existing method, product whatever, instead of simply redirecting the user back to the startpage.

I blogged about using the OnMissingTemplate method a while back to do just what you are planning

if you don't have access to your host to add the isapi filters for your URL then the onmissingtemplate is really your only choice to do SES the way you want to do it.

Comment 5 by Raymond Camden posted on 6/26/2009 at 11:01 PM

@Steve: I'll ditto Gary. For cases where the URL does not match an expected pattern you want to log the request at minimum. This would let you see what's being requested that you aren't handling. Are folks coming to a typo version of your product name? Support the typo. Are folks looking for your competitors product? Create a page for that and talk about why your product is better.

Comment 6 by Steve Gongage posted on 6/29/2009 at 6:23 PM

@Gary & @Raymond

Gotcha, that makes sense. I had planned to take them back to a generic start page and if reasonable, try to suggest a page they might have intended to go to, but I can see the logic behind at least logging the request.

Thanks for the advice!

Comment 7 by Matthew posted on 2/19/2010 at 3:37 AM

I like the way that mangoblog is doing their rewriting (
Are they using the missing template method or something else?
I like how whatever I have listed in the db for my articles appears in the URL.
Could someone help me understand the code needed to recreate this? I need to use clean URLs on other projects, but there does not seem to be a good, concise template set for this task. Not sure why.

i'm on CF7

Comment 8 by Raymond Camden posted on 2/19/2010 at 3:44 AM

BlogCFC does it too. ;)

There are a variety of ways of doing it. Here is one discussion: http://www.coldfusionjedi.c...