Want to allow someone to shortcut their way to a particular part of a website? Jonathan Yong, one of our Premier Field Engineers from Malaysia, shows you how!
Problem: I have a url or domain that is very long! How can I create a shorter url that acts as an alias, which maps to a subfolder under the long url?
Example: Instead of going to www.verylongurl.com/folder, I want people to simply go to www.shorturl.com.
Answer: You can use the IIS URL Rewrite module to create a rule which maps one url to another.
Prerequisites: This solution only works with IIS 7 and above.
Details: In the following, I will show you step by step how to accomplish this. There’s also a sample file included (see the download link at the bottom of this page) so that you can try this in your own environment.
Download and install the IIS URL Rewrite module from IIS.net.
If IIS Manager is running when you install URL Rewrite, you will need to close and reopen it in order to see the URL Rewrite configuration tool icon.
Next, I will copy the files and folder necessary to set up my web site.
Don’t close the command prompt yet. We still need it for subsequent steps.
I will create a web site which maps to the folder above and has two bindings, using host headers.
From the command line, run 02-create_site.bat to create the web site.
On the Internet, we’d need to add both hostnames to DNS so that users can surf to the site.
In our test environment, we simply add this to the HOSTS file on any computer we’re testing from.
We will now create the URL Rewrite rule which maps the short url to the long url.
In the URL Rewrite configuration, click on the Add Rule(s) link in the Actions pane on the right hand side.
Select the Blank rule template and click OK.
In the Edit Inbound Rule screen,
Click the down arrow to expand the Conditions title, then click Add.
In the Add Condition dialog,
Scroll down further to the Action section.
Click the Apply link on the top right of the Actions pane.
The configuration is saved to the web.config file in your web site folder. You may open this web.config file to review how the configuration is being created under the hood.
Let’s review what we just did from step 8 to 11:
If you browse to http://shorturl.com/abc.htm, the url will rewrite to http://shorturl.com/subfolder/abc.htm.
However, if you browse to http://verylongurl.com/abc.htm, the url will not be rewritten because it does not match the host name we are looking for, which is “shorturl.com”.
To see this in action, browse to the following pair of urls and you should see that each pair will show you the same page.
You can learn more about URL Rewrite module here.
Download the sample file here:
Hi, Thanks for the great post.
I have a challenge. Currenlty one of our application is running on Port 80. (Ex:
But few of the pages are hard coded to use a different port (Ex:
How can we remove the port number 1025 from the URL using URL Rewrite?