So today I had some time to kill and decided to geek out on our blog. We just purchased the ISAPI Rewrite extension for one of our projects and since we had to buy the Full version (the one which works with multiple domains in IIS) I figured it was high time to utilize it in the name of Digital Positions!
The ISAPI Rewrite is an ISAPI extension for IIS web servers which allows you to transform the url's of your web site from one format to another. For example all of our blog url's used to look like:
/index.cfm?article=100000
/index.cfm?author=100000
/index.cfm?keyword=100000
/index.cfm?archive=7/1/2005
But thanks to the rewrite capability of ISAPI Rewrite we now have these great Search Engine friendly URL's
/article/100000.cfm
/author/100102.cfm
/keyword/100000.cfm
/archive/07012005.cfm
Upon my initial look, it was great to not have the equal sign (=) or question mark(?) or ampersands (&) anywhere in the URL, but it was still lacking. One thing a site can do to increase it's ranking on most search engines is to use real words for file names. So while this numeric format was good for Search Engines in general it wasn't that great overall and was horrible for human readability. So I spent some extra time converting our code base to use words instead of numeric values. The final version of our URLS now look like so and they use real words:
/article/Designing_your_site_for_the_web.cfm
/author/Eric_Jones.cfm
/keyword/ColdFusion.cfm
/archive/07012005.cfm
Using the ISAPI rewrite is super easy and it comes in two flavors; full and lite. The lite version is free for a single web site running solo on an IIS web server. If you have more than one virtual site you'll need to pony up for the full version (which is still under $75!). The ISAPI Rewrite tool works using Regular Expression and a configuration file. Writing the Regular Expressions wasn't as hard as you might think since you are dealing with some very basic text strings. Here's an example of the code I used for the article links:
RewriteRule /article/([a-bA-z0-9_\?\']{1,}).cfm /index.cfm\?article=$1 [I]
The above code basically says looks for a url which contains the "/article/" and then immediately after that it contains an unlimited number of letters, numbers and underscores, "([a-bA-z0-9_\?\']{1,})" which is then followed by a ".cfm". IF the ISAPI Rewrite finds this string it takes the portion between the opening and closing parentheses "([a-bA-z0-9_\?\']{1,})" , dumps it into a variable called $1. Then, as you can possibly see from the latter portion of the code, the value of this variable is appended to my "/index.cfm?article=" url. So "/article/Designing_your_site_for_the_web.cfm" becomes "/index.cfm?article=Designing_your_site_for_the_web"
All of this is handled before the browser request is actually sent fully to IIS or the ColdFusion server. So while you see a URL of "/article/Designing_your_site_for_the_web.cfm" the IIS Server and ColdFusion server sees the URL as "/index.cfm?article=Designing_your_site_for_the_web". Which means no 404 errors are logged and nobody throws a fit.
There are other ways to create Search Engine Friendly URL's but when you want to create them quickly and without having to rewrite your code base the ISAPI Rewrite is a great thing to have!
Comments (0)