A trick to set up 301 url redirect in Sitecore

Recently I am working on a task to redirect whole bunch of page urls to a new location. I want to preserve all of the links from search engines. So I need to make sure that the old links give a 301 (Moved Permanently) response back. This will allow the web crawlers to update their databases with the new links as well as keep the old links working in the meantime.

I downloaded the Sitecore 301 redirect module from marketplace. It comes up with three types redirect setting:

  • Exact Match Redirects
  • Regular Expression Redirects
  • Rules based Redirects

It sounds very straightforward. I started to set a redirect with type “Exact Match Redirects”. For example:

http://somesite.com/en/oldpage.aspx –> Sitecore/Content/somesite/newpage.

But no matter how I tried, the redirect just didn’t happen. What’s wrong?

After reading the document and tried several more different scenarios, I found how the redirect module works. Sitecore allows customizing the rendering pipeline which is exactly the redirect module does. This module kicks in right after Sitecore tries to resolve the item for the request. If Sitecore resolves the item, this module doesn’t do anything. Otherwise, it runs through the rules in the above 3 matching order.

One important thing I found is, Sitecore’s language processor resolves the language before rendering happens by retrieving the language flag in url. That means when this redirect modules kicks in to compare the match url, the language has already been solved and the flag in url is removed. For example above old url becomes http://somesite.com/oldpage.aspx. That’s why my previous redirect settings failed. After I removed the language flag from the url, it succeeded.

Another tip to make the redirect work is, make sure the old link is dead/disabled.

This entry was posted in Information Technology, Sitecore and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s