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.


August 15, 2008

10 Downing Street website re-launched

Filed under: Politics,Web — duncan @ 12:32 am
Tags: , , ,

The 10 Downing Street website has been given a Web 2.0 makeover and relaunched. Not without some teething problems however; the site was down for some time on the 12th, it had/has many 404 errors, and some of the HTML is a bit dodgy for such a high profile site (despite claims of attempting WAI level AA compliance).

From the BBC article:

A Downing Street spokeswoman denied the site had crashed. But she said users on some servers might experience glitches “for the next 48 hours“. “It is just what happens when you launch a new website,” she added.

Sorry, but that’s just not true. I suspect I’ve worked on more website launches than the Downing Street spokeswoman, and having glitches for the first 48 hours isn’t just what happens. If it does happen, it’s usually for a reason – lack of time committed to testing.

While checking the site for some basic HTML errors, I came across the following anomalies. Firstly, discovered this 404 page had a link to an internal IP address that obviously isn’t going to work (the ‘home’ link in the breadcrumbs). Trying to play around with the 404 error handling, I appended ‘blah’ to the URL, and got this weird page (redirects to http://www.number10.gov.uk/Page10276). I also got similar results if I appended 404 on the URL (redirects to http://www.number10.gov.uk/Page6871). Note that second page has different details from their standard 404 page.
Why not try it yourself and see what other URLs work 😉

Number 10 Blah

Number 10 Blah

This isn’t really too surprising; they’re obviously doing a bit of SEO URL-rewriting. It’s more the fact that there’s seemingly test content still up there from 2005 and 2006.

I liked this too – on their Privacy Policy, they have links to all the different domains the site is available from. Guess how many of these work:

Currently, the last three don’t seem to…

Blog at WordPress.com.