4

I'm using the 301 Redirect Module in Sitecore 8.2. When a user creates a new item, it is automatically placed under the parent in alphabetical order, and then when they move it to the order it's actually supposed to be in (by dragging the item to the right place), a redirect is generated that redirects from the current path to the current path:

enter image description here

Is there a way to prevent the redirect module from generating a redirect when the path has not changed?

1
  • I noticed that the redirect url and the item path are different. One has dashes in it while the other does not. Curious if that matters. Commented Sep 6, 2018 at 15:40

1 Answer 1

4

This appears to be an issue with the Redirect Module itself but I fixed it by cloning the module repo and modifying the OnItemMoved method in AutoCreateRedirectOnMove.cs:

public class AutoCreateRedirectOnMove
{
    protected void OnItemMoved(object sender, EventArgs args)
    {
        //ensures arguments aren't null
        Assert.ArgumentNotNull(sender, "sender");
        Assert.ArgumentNotNull(args, "args");

        if (Sitecore.Configuration.Settings.GetBoolSetting(Constants.Settings.AutoGenerateRedirectsOnMove, true))
        {
            Item item = Event.ExtractParameter<Item>(args, 0);
            ID oldParentID = Event.ExtractParameter<ID>(args, 1);

            // ADDED BY ME
            if (oldParentID == item.ParentID) return;
            //

            using (new SecurityDisabler())
            {
                CreateRedirectItem(item, item.Database.GetItem(oldParentID));
            }
        }
    }

The line I added prevents a redirect from being generated if the parent of the item has not been changed. I compiled the solution, copied the resulting SharedSource.RedirectModule.dll from the bin and placed it in the bin of my project, overwriting the existing dll.

EDIT: The project owners have merged the fix into their repo so it should be resolved with the next release on the Sitecore Marketplace

Your Answer

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

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