One guy recently posted a question on StackOverflow on how to use Redirect Module. So I decided to reply about that, but thought it is a good topic for a blog post.
First of all, he probably meant a Sitecore Redirect Module from Marketplace. I have heard multiple complaints on that one and that it doesn't work as expected, moreover it seems to be discontinued.
Luckily, there are many forks of that one on the internet, as ability to control 301 redirects right from Sitecore is well in demand. I want to suggest probably the best fork I found and am successfully using myself - done by Chris dams and Max Slabyak. Why?
How to get it: all you need including sources, packages for all versions and documentation is available from GitHub by this link.
- module is developing with time - just recently there was new version 1.4 that introduced ability to specify various status codes
- good documentation included
- sourcecode is available on Github under MIT license - feel free to use imn your commercial projects
Let's now create a sample redirect from a virtual URL of non-existing page to some page item in Sitecore.
We want everyone who tries accessing http://our.sample.website/pagename (note that there is no pagename item in Sitecore) to be redirected to another existing page that sits at /sitecore/content/Home/landingPage in Sitecore. For the first time, for sure, as 301 redirects are cached in user's browser and next time he/she would be taken directly to landing page (by browser).
/sitecore/system/Modules/Redirect Module folder in Sitecore create a new redirect pattern called
- Set requested expression to
- Leave response status code equal 301
- Set source item to the actual page item serving that redirect request
- Do not forget to publish redirect pattern (and module itself if not yet)
A screenshot below shows how it looks in Sitecore:
Hope you find that useful!