IIS Server Tutorials: Using URL Rewrite to Fix URLs in IIS
The Alpha Anywhere Application Server for IIS is currently in beta. In this first post in a series of IIS server tutorials, lead architect Terry Smith answers questions from beta testers. For more information on the Alpha Anywhere Application Server for IIS, check out this overview webinar on-demand.
A developer recently asked, “Is there a way to hide page extensions in URLs when running under the Alpha Anywhere Application Server for IIS? For instance, the end user types https://www.mydomain.com/mypage and the mypage.a5w page is processed and returned.”
The answer is “Yes”. It can be done using an IIS component called URL Rewrite. The IIS component ecosystem is one of the benefits of using IIS.
URL rewriting is a very useful feature for doing tasks like making public URLs prettier (e.g. not including file extensions) or for doing something more advanced like making sure old bookmarked URLs still work when a backend completely changes. In the latter case someone may have bookmarked http://www.mydomain.com/1999app/cgi-bin/help.exe?topic=contents but the new system needs the URL to look like this https://www.mydomain.com/help2014/contents. This example is contrived, but does happen in practice and demonstrates what can be done with URL rewriting.
To answer the “hide page extensions” question, after installing the URL Rewrite component you can define a rewrite rule to add a .a5w extension to a URL’s path when an extension doesn’t exist. IIS will examine the URL for each request that comes in for the site and if it matches the rule pattern will rewrite the URL so continued processing in IIS will see the rewritten URL instead. By the time the URL makes it to the Alpha Anywhere Application Server for IIS it will have the .a5w extension.
There are also outbound rules that you can use too. You would use an outbound rule to strip off the .a5w extension on links. This takes time though as the entire response body needs to be processed. It might be better to make your links not have .a5w extensions to begin with.
One caveat is that right now working preview and live preview in Alpha Anywhere Developer Edition do not use IIS so testing a web app without .a5w extensions would have to be done to a published web application on an IIS server.
To install the URL Rewrite extension, select the server node in IIS Manager, click on the Get New Web Platform Components link and then search for URL Rewrite.
Once it is installed you will most likely need to close IIS Manager and then restart it to see the URL Rewrite icon.