URL Rewriting with IIS and Umbraco
1 Comment Published by boris November 26th, 2008 in technology, umbracoAt Cultural Care Au Pair we use Google Analytics to track the sucess of our campaigns both online and offline. Google provides a nice url builder tool that generates links tagged with our various campaign attributes. Here’s the problem though, the links end up looking like:
http://www.culturalcare.com/default.aspx?utm_source=testSource&utm_campaign=testCampaign
That’s quite an ugly url for something like a postcard campaign. Luckily umbraco includes a full url rewriter that can help us easily transform that into something like www.culturalcare.com/postcard
1. Configure IIS for wildcard application mapping. This allows ASP.NET to process extension-less urls (such as /postcard/):
- right click on the umbraco website and select properties
- go to the “home directory” tab and click “configuration”
- in the “wildcard application maps” insert the ASP.NET dll (something like C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll ) and un-check “verify that file exists”
2. Edit /config/UrlRewriting.config in your umbraco folder
- Change the top tag to ensure that you don’t have any conflicts with other extension-less urls (like /umbraco)
<urlrewritingnet rewriteOnlyVirtualUrls="true" contextItemsPrefix="QueryString" defaultPage = "default.aspx" defaultProvider="RegEx" xmlns="http://www.urlrewriting.net/schemas/config/2006/07" ><rewrites> ... </rewrites> </urlrewritingnet>
- add your rewrite rules following the example in the file or the documentation at urlrewriting.net. For example, if I wanted to redirect /postcard/ to /default.aspx?utm_source=testSource&utm_campaign=testCampaign I would add the following rule:
<add name="postcard" virtualUrl="^~/postcard/?$" redirect="Application" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/default.aspx?utm_source=testSource&utm_campaign=testCampaign" ignoreCase="true" />
- Note that the & needs to be written as & in the destination url.
- If you’d like to redirect to a different domain, virtual url and redirect need to be specified accordingly:
<add name="offsite" virtualUrl="^http\://(.*)my.domain/redirect/?$" redirect="Domain" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="http://offsitedomain.com" ignoreCase="true" />
Enjoy!