How To Set-up Page Redirects In Umbraco

A company’s website is kind of like a living entity; over time the CMS might change, pages might move around and even whole sections might get deleted. As part of this change, Url’s for existing page will change. This has happened on pretty much every project that I’ve ever worked on. When it comes to creating re-direct in Umbraco we have several options. In today’s tutorial, I’m going to cover some of the more frequently used techniques to create a re-direct in Umbraco.

UrlRewritingNet.UrlRewrite

Out of the box, Umbraco comes with ‘UrlRewritingNet.UrlRewrite‘. One word of caution before you use UrlRewritingNet.UrlRewrite is that historically, it has had some bad performance issues. I would recommend reading this article before you decide to use it.

If you are only creating one or two redirects and you don’t have a massive amount of traffic, then it is more than fit for purpose. To get started, in your website’s webroot, have a look in ‘Config’ -> ‘UrlRewriting.config’. This is the file that you will use to define the re-direct. Like most re-direct packages, the rules are configured by rules. For example,

<add name="xmlsitemaprewrite"
virtualUrl="^~/sitemap.xml"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="/XmlSiteMap"
ignoreCase="true" />

The above rule, if you can’t guess, transforms a request from www.website.com/sitemap.xml to XmlSiteMap.

Url Rewrite

Url Rewrite is probably the most used re-direct tool. It’s built by Microsoft and works directly in IIS. When you add a rule in IIS it adds it directly in the website’s web.config. To get started with Url Rewrite, you need to download it from here. You will need to install it on all of your environments, so dev, test, staging and live.

When the plug-in is installed, if you open IIS you should see the Url Rewrite option

Umbraco_Redirects_1

If you click on this in the top right you should see an option called ‘Add Rule(s)..’

Umbraco_Redirects_2

When you click on ‘Add Rules’ you should see a screen that gives you a lot of options. In most instances you will just want to create a new inbound blank rule.

Umbraco_Redirects_3

The next step in the process is actually defining the rule.

Umbraco_Redirects_4

Like UrlRewritingNet.UrlRewrite you can define your Url’s using Regular expression and get as complex as you want to. If, on the other hand, like me, in most cases you just want to create a simple redirect, then the process is pretty easy. Create a name for your rule, this can be anything you want. In the pattern add in the Url, minus the website domain, so www.website.com/sitemap.xml would be sitemap.xml. In the action properties put the Url you want it to re-direct to, in my example I’m redirecting to www.website.com/XmlSitemap which translates to XmlSitemap. Click ‘Apply’ in the top right and job done!

If you look in your website’s web.config you should now be able to see an entry similar to this:

<rewrite>
<rules>
<rule name="Sitemap Re-direct">
<match url="sitemap.xml" />
<action type="Rewrite" url="XmlSitemap" />
</rule>
</rules>
</rewrite>

If you prefer to work in your web.config you can just copy the section and change it to meet your needs. Simple!

Conclusion

In today’s tutorial, we’ve covered two methods of creating re-directs within Umbraco. The first is the solution that comes out the box, UrlRewritingNet.UrlRewrite and Microsofts Url Rewrite. I personally wouldn’t recommend using UrlRewritingNet.UrlRewrite. It might come with Umbraco but it’s not as widely used or supported as Url Rewrite. Url Rewrite is used on thousands of servers, can be used in IIS and has good documentation. Url Rewrite is pretty easy to use, install it on all of your servers then either using the GUI or your websites web.config define your rules. Enjoy!

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

1 reply

Trackbacks & Pingbacks

  1. […] If you agree with me then I’m going to quickly show how you can enforce WWW Url’s within a few minutes using Url Rewrite. If you want a more detailed guide on how to set-up Url Rewrites in Umbraco then I suggest you read, How To Set-up Page Redirects In Umbraco. […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *