Back to all articles

How to turn Sitecore 8 aliases into redirects

howto 4
James Simm
James Simm
Head of Engineering
Length
3 min read
Date
22 June 2015

Redirects are a  common feature that our clients request for many reasons, such as their URL structure changing or SEO requirements. Redirects are extremely handy to have, and even better when a non-technical user can create them without having to rely on IIS modifications.

Sitecore has a few options in this situation, for example, I’m a big fan of the Sitecore URL Rewrite Module by Andy Cohen. If you haven’t checked it out already, it provides a lot of the standard IIS rewrite module functionality, but through Sitecore instead.

Another way of implementing redirects if you don’t want something as heavy duty as the URL Rewrite module, is by over-riding aliases in Sitecore. You can provide redirects to the user and at the same time, restrict a feature of Sitecore that can be misused.

Sitecore aliases

Often people don’t realise the SEO implications of having two URLs for the same page, which is exactly what aliases do. While you could avoid a situation like this by implementing a canonical URL, as recommended by Google, in my opinion it’s much better to simply hijack this functionality and use it to provide redirects instead.

So, what to do?

Well, if we’re going to hijack aliases, you’d expect us to have to write huge chunks of code and override all kinds of classes, right?

Nope! All we have to do is write a single pipeline modification that comes in at just 60 lines of pretty simple code.

Without further ado, here’s all you need:

CODE IS UNAVAILABLE, CAN BE FOUND HERE

After that, you just need a way of replacing out the alias resolving pipeline with our new version. Since we know what we’re doing, let’s add this as an include and patch out the original pipeline, like so:

CODE IS UNAVAILABLE, CAN BE FOUND HERE 

Of course, don’t forget to swap out the namespace for your own instead of ‘launch Sitecore’. Once that’s done, it’s pretty simple to see the results; open your network tab and you’ll see that your aliases have turned to redirects.

More?

View all insights

Questions?

Global SVP Technology & Engineering

Jonathan Whiteside

Stay in touch!

Personalize your experience

We use functional cookies to make the website work properly, analytical cookies to measure your behavior and marketing cookies for ads- and content personalization. We collect data on how you use our website to make our website easier to use, but also to tailor or personalize communication in advertisements, on our website or apps. Data collected through marketing cookies is also shared with third parties. By clicking accept you agree to this. More information? Read our cookie policy.