Most IIS admins have at least a passing familiarity with the concept of URL rewriting, which is a way to adjust...
the mapping between a particular URL’s request and the handler for that request.
For example, if you request a file named .ASPX, it’s handled by the ASP .NET handler on the server. If you request a static file like an .HTM document or an image, it’s sent to a handler for those types of files (which typically just streams the file out to the client). And so on.
But sometimes you’ll want to handle URL requests with a little more flexibility. For instance, you might want to take URLs that don’t have an actual file extension -- such as http://yourdomain.com/faq -- and redirect them to one that does. You might also want to route some requests to a different server entirely or provide additional manipulation for certain file types before they’re served.
Earlier versions of Internet Information Services (IIS) did not have a native URL-rewriting mechanism, so a number of folks crafted their own add-ons for IIS to accomplish this. In fact, IIS 7.5 with Windows Server 2008 R2 still doesn’t have its own URL-rewriting module, although Microsoft offers one as an add-on (dubbed URL Rewrite).
Ionic’s Isapi Rewrite Filter, or IIRF for short, was written to make up for the shortcomings of URL Rewrite and many other third-party URL rewriter tools. It’s a free open source utility under the Microsoft Permissive License, so it costs nothing to use or deploy and the source code can be applied to other work. It uses the Perl Compatible Regular Expressions library to perform regular expression-style (regex) matching. Therefore, the vast culture of regex strings developed in the Perl world -- where regex reigns supreme -- will work well with it. The IIRF tool works with just about any Web application system, including Perl, PHP, ASP, ASP.NET, JSP and Microsoft SharePoint. It doesn’t depend on the .NET library for any of its functionality, so those who don’t want to use or depend on that library don’t have to.
Once installed, the Isapi Rewrite Filter is configured through two INI files -- one for the entire system (IirfGlobal.ini) and another for each virtual directory or IIS application (IIRF.ini) you want to use. These INI files can contain rules for rewriting URLs that are quite similar in format and functionality to the RewriteRule commands in Apache’s mod rewrite engine. The IIRF tool even uses the command RewriteRule itself, so those coming over from Apache will find it somewhat familiar. IIRF also supports both redirecting and rewriting side-by-side, and can also work as a request-proxying system on top of that.
A good grasp of regex is a key component to understanding how URL rewriting works, so I strongly recommend getting familiar with the basics and trying out the IIRF module in a provisional way before deploying it in any production environment. Once you’ve mastered the essentials, check out this really good rundown on how regular expressions work and how “flavors” of regex vary as well. Finally, I recommend looking into INI file examples to get started with some common tasks (blocking requests by user agent; mapping a virtual host to a subdirectory; automatically migrating domain names, etc.).
You can follow SearchWindowsServer.com on Twitter @WindowsTT.
ABOUT THE AUTHOR
Serdar Yegulalp has been writing about computers and information technology for more than 15 years for a variety of publications, including InformationWeek and Windows Magazine.