When not to use URL Rewrite in IIS Posted by Mischa S.

Back

Date: March 14, 2012

Most development shops focus on a specific language.  We happen to focus on Coldfusion (though we also do PHP and ASP.NET C#), and one of the issues with CF's built in onMissingTemplate() function (in application.cfc) is that it doesn't handle requests to missing files, just missing coldfusion file requests.

Example:

  /somefolder/missingtemplate.cfm - handled by onMissingTemplate() flawlessly.
  /somefolder/missingtemplate.html - onMissingTemplate() fails impressively

So, I thought to myself, "Self, use an outbound URL Rewrite rule to catch the 404 error and forward the user to a pretty page that says, DOH, no page here amigo.  Sorry."

Now, I got about 30 minutes into reminding myself about dealing with regex, and crafting and testing the rule when I remembered how easy this was in IIS6 and I stopped dead.  There has got to be an easier way to do this.

Enter "Error Pages" in IIS 7! 

<httpErrors>
	<remove statusCode="404" subStatusCode="-1" />
	<error statusCode="404" prefixLanguageFilePath="" path="/index.cfm?go=vv:home.err404" responseMode="ExecuteURL" />
</httpErrors>

 

No matter what someone enters into your site now, it will be caught and your adorable little error page ('index.cfm?go=vv:home.err404' in our case) will be shown.  This is completely agnostic of the file extension someone puts in.

go