Duncan's blog

March 25, 2009

Custom 404 page with ColdFusion and IIS

Filed under: Coldfusion — duncan @ 8:51 pm
Tags: , , , , , ,

This is one of those techniques that I’ve been using for years, and only just discovered a simple mistake in it. However, I think this mistake might be quite common, so decided to blog about it.

If you’re using ColdFusion and IIS as the webserver, you can either use IIS’s default page for handling 404 (page not found) errors (and any other error type). Or you can specify a page of your own. By specifying your own page it makes it easy for you to have a 404 page that matches the design and functionality of your website.

To do this is simple. In IIS, go to the Properties screen for your website. Go to the Custom Errors tab. There you will see a list of all different types of errors you might generate. Scroll down the list until you find the 404 error.
Custom Errors tab in IIS
Select it and click Edit. Change the type to URL, then put in the relative path to your own 404 page.

Simple, right? You’ll see the above method in many ColdFusion articles, and I’ve done it like this for years. However, there’s one vital step being missed out. I only discovered this when trying to register my site for Google Webmaster Tools. You have to verify your site by uploading an HTML file or adding a custom meta tag to an existing page. However it seems the Google bot also checks your 404 page at the same time. I got the following error message:
We’ve detected that your 404 (file not found) error page returns a status of 200 (Success) in the header.

?! To check this, I went to mysite.com/blah, then using the Web Developer Toolbar in Firefox, checked View Response Headers. Which gave me the following information:

Connection: close
Date: Wed, 25 Mar 2009 20:41:55 GMT
Server: Microsoft-IIS/6.0
Content-Type: text/html
Page-Completion-Status: Normal, Normal

200 OK

Oops, that should say 404 not 200! It doesn’t take much to fix it. At the very top of the custom 404 page (before any <doctype> or <html> tag) just add in:

<cfheader statusCode="404" statusText="Not Found">

Checking the Response Header Information again following that change then correctly returns:

Connection: close
Date: Wed, 25 Mar 2009 20:41:30 GMT
Server: Microsoft-IIS/6.0
Content-Type: text/html
Page-Completion-Status: Normal, Normal

404 Not Found

and Google then successfully verifies the website.



  1. Hello Duncan,

    Thank you so much for your post, this article has helped me to solve http status code problem.

    Now, I will read your whole blog it seems more interesting

    Comment by Rajesh Mergu — June 17, 2010 @ 3:05 am | Reply

  2. Hi Duncan,

    I am using same pattern for our agents custom URLs.
    However, they are not appearing in Google search.Even if, I type their custom URLs along with domain.
    I submitted their URLs in XML site map too.
    Any clues.

    Thanks in advance

    Comment by Srinivas — August 11, 2010 @ 7:20 pm | Reply

  3. You want your 404 pages to appear in Google search? Or do you mean you’re using a 404 page to handle custom URLs? If the latter, there’s probably a better way to do it. Can you give me more information about how you’re handling your custom URLs?

    Comment by duncan — August 12, 2010 @ 1:20 am | Reply

    • I am using 404 page to handle custom URLs.In addition to that , I want to show up that results in Google search if the user types agent Custom URL along with domain in Google.

      404 page code as follows,

      WHERE customURL =



      Comment by Srinivas — August 12, 2010 @ 7:09 am | Reply

      • Oops code stripped,give me your mail id.will send you more details.

        Comment by Srinivas — August 12, 2010 @ 7:34 am

  4. duncancumming AT gmail DOT com

    Comment by duncan — August 12, 2010 @ 8:21 am | Reply

  5. Thank you for your post. I followed your directions, but it only seems to work for files not found of .HTM or .HTML extensions, not .CFM or .CFML extensions. Is there something else to be done to respond on a not found .CFM file?

    Comment by Larry Larson — April 10, 2012 @ 7:05 pm | Reply

  6. In the CF Administrator you probably need to update the Missing Template Handler. Read this: http://helpx.adobe.com/coldfusion/kb/coldfusion-mx-configuring-missing-template.html

    Comment by duncan — April 11, 2012 @ 9:49 am | Reply

    • I know this is an old blog item but I have a question. If you configure the 404 in missing template in cf admin, won’t that serve the same template for all of your sites thus defeating the purpose of a custom per site 404 error page? I’m running cf 11 and it’s 8.5. This is a very frustrating problem that I haven’t been able to find a solution to on the Web.

      Comment by Brett — December 3, 2015 @ 11:42 pm | Reply

      • Hi Brett. The URL you specify to the /missingtemplate.cfm in both IIS and CF Admin uses a relative path, so couldn’t you create a missingtemplate.cfm file in each of your sites?

        Comment by duncan — December 4, 2015 @ 9:29 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: