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