4

I've been tasked with renaming a number of content items. That should be simple enough, but because these items are pages, the client also wants to have redirecting.

There is already installed URL rewrite module in the instance, which the client uses for a couple of simple redirect rules. Unfortunately, redirect rules will not work in my case, because some renamed items might also have descendants that are also being renamed. So having an item's path being changed to something similar to the example below will most certainly happen:

{oldname1}/same/{oldname2}/same -> {newname1}/same/{newname2}/same 

That leads to think that there are 4 major cases I have to cover:

CASE 1:

Request:                           Redirected to:
{oldname1}/same/{oldname2}/same -> {newname1}/same/{newname2}/same 

CASE 2:

Request:                      Redirected to:
{oldname1}/same/{oldname2} -> {newname1}/same/{newname2}

CASE 3:

Request:            Redirected to:
{oldname1}/same -> {newname1}/same

CASE 4:

Request:      Redirected to:
{oldname1} -> {newname1}

My initial idea was to create an inbound rule that would replace one renamed item at a time and redirect. For example: Using case 1- when we receive {oldname1}/same/{oldname2}/same request we will have an inbound rule that would redirect to {newname1}/same/{oldname2}/same. Then another inbound rule will handle the {oldname2} value and redirect to {newname1}/same/{newname2}/same( we don't expect more than 2 redirects per request).

So I started trying to implement that. I've created an inbound rule that matches the pattern: ({oldname1})(?!\/.) and following this article (http://avillenas.com/post/url-rewrite-module-for-sitecore-part-2). I've created a redirect rule and wrote https://{HTPP_HOST}/{newname1}/{C:1} inside the Rewrite URL field, I've renamed one test item and started testing.

No matter what I tried the redirect rule would not work unless I use internal link that leads to the newly renamed item. This does not help me with my initial idea, because all of the request containing {oldname1} then got redirected to {newname1}(e.g. requests like{oldname1}/same/{oldname2}).

My questions are - how would you actually handle the redirecting? Would you go for another implementation? If yes then what I am doing wrong?

Also I have to note that I do not have access to the codebase, but I do have full admin rights in Sitecore.

P.S. I found this Question , but I believe that my case is different enough to deserve its own question

1

2 Answers 2

1

Installing Constellation.Feature.Redirects gets you a new Sitecore app for the Sitecore Desktop called Redirect Manager. This application allows you to create, update, export, and import a list of marketing redirects.

You also get an Item Template that you can use to insert a Page Redirect anywhere in your content tree. This allows you to create short URLs that link to deeper content, or to host a URL within a given section of your site that points to something external to that branch of the content tree.

Installation Constellation.Feature.Redirects is managed via NuGet.

In Visual Studio, fire up the Package Manager console and install into a Web Application project:

PM:> Install-Package Constellation.Feature.Redirects

Once you will install this library you will get the option Redirect Manager in Desktop from Launchpad. enter image description here

Click on the redirect manager and it will redirect you to the new Window:

enter image description here

In the Redirect Windows manager, you can perform the below operation

  1. Adding a New Marketing Redirect
  2. Editing Existing Redirects
  3. Importing and Exporting Marketing Redirects

See the blog post for more details: Redirects

Some issues I have faced and with the help of the module owner I have resolved and I wrote that solution in this blog you can refer to, maybe it can help you. URL Redirects Module in Sitecore

0

I followed the link to the article you referenced, and it seems you are using the Url Rewrite Module (by Andy Cohen): https://github.com/iamandycohen/UrlRewrite

In your question, you state your initial problem when testing out the module is this pattern:

({oldname1})(?!\/.)

Redirects all requests, including those you do not want. i.e. {oldname1}/same/{oldname2}

The reason for this is that the rule you have created has 'too generic' pattern. It states any incoming URL request that matches the pattern {oldname}/xxx should be redirected using your action. So it will match anything starting {oldname}.

I believe instead, you should have more specific rules. Taking your case #1 as an example. Try something like this pattern instead:

{oldname1}/(.*)/{oldname2}/(.*)

And then redirect to an action as below:

{newname1}/{C:1}/{newname2}/{C:2}

Then when it comes to dealing with case #2. Instead of using a regular pattern to detect the incoming request. Use a simple redirect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.