Mod_rewrite is a very handy module that is included with most Apache installations and allows you to achieve some rather nifty stuff with a few lines in the .htaccess file.
IIS 6 doesn’t have a direct mechanism to compete with this but you can still achieve similar results using IIS’s error handling mechanism.
Start off by adding an error handling URL, in IIS Manager open the web site’s properties and select the Custom Errors tab:

Scroll down and find the 404 HTTP error entry, and then click on the Edit button.

Select URL from the message type drop down and enter your URL in the File: box, say “/404handler.asp”. NB the leading forward slash is required.
Click OK to save this and click OK in the properties dialog to apply the change to the website.
Now you need to create your 404 handler.
The first thing to note is that that in Classic ASP, Response.QueryString will hold a value which looks like the following:
404;/url-that-doesnt-match-a-file?x=2
Which means you wont be able to use Response.QueryString(“x”) to read the value 2, so you may want to refrain from using query strings, which is normally one of the reasons you are looking at implementing a URL rewrite scheme.
So at the start of the handler the first thing you will need to do is look at Response.QueryString and check that the first four characters are “404;”
If that’s the case then use the remainder of the string as the URL to be rewritten.
How you do this is really up to you, a simple scheme I’ve used is a look up table in the database to find the name of a script and then use System.Transfer to switch control to it. Remember that no variables declared and assigned in the first script are available in the script called by System.Transfer, but the Request object is still valid so that isn’t really a problem.
You can also use the same table to issue redirect to your SEO friendly URL if someone accesses it directly.
Related material:
- Configuring Custom Error Messages (IIS 6.0)
- 403.18: “The Specific Request Cannot Be Executed from Current Application Pool.”
Tags: Classic ASP, IIS 6, URL rewrite
