SaaS CMS has officially launched! Learn more now.

Updating internal links at scale



Thanks for hosting the forum, it's a great resource for a newcomer to Episerver like myself. 

I wanted to ask about internal linking and how internal links are used in the Episerver CMS backend, which is done by two methods;

  • Using page selection tool
  • Using HTML editor to manually link to the page

Some of our pages currently change a lot on a yearly basis, so there is an ongoing manual task to update internal links from the older pages to new pages. It's a time-consuming process, so we have tried a frontend update via JS but it's not specific enough, so blankets all links but not able to not update if necessary (without excessive scripting).

In this example, we have a link to a page that is selected in the Page selection tool (see below):

For example, we know that there are 20 instances where this page is linked across the different pages and we know the new destination URL, not necessarily via page ID.

Is there any way to update all links from the old page to the new page?

Many thanks in advance

Apr 06, 2021 12:19

You can use Shortcuts. Create a shortcut on Old page that redirects the user to the new page. 

Apr 06, 2021 12:55

Thanks for the reply, so we are looking to reduce the number of 301 redirects at the same time. So I don't think shortcuts would be sufficient for this.

In total, there are about 1000 links also, so we are currently using Custom Redirects Manager to go A > B, but due to the volume, it's contributing to a large portion of 301 redirects which need to be reduced from an SEO perspective.

Apr 06, 2021 13:17

You can use the ContentSoftLinkRepository as described here to find all the link to a piece of content. Therefore you can either build a tool for the admin to allow these to be updated from one item to another or build some sort of marker on a page/content and scheduled job to update. 

Apr 06, 2021 13:57

Hi Scott,

Thanks, I will check that out...

This would be for static HTML or only those through the page selection tool?

Apr 06, 2021 14:46

The ContentSoftLinkRepository should return any content that's linked in the CMS from another place in the CMS, it doesn't have anything to do with static HTML but should work I believe for links set in the XHtmlString type (the WYSIWYG editor type)

Apr 06, 2021 14:52

Apparently.. the link is not what we are looking for.

So say I have URL A (a final destination), we know 122 pages link to URL A. This would be linked to from a WYSIWYG editor using the page selection dropdown.

We need to update the links automatically, to now go to URL B.

Apr 09, 2021 11:41

Yes so the ContentSoftLinkRepository was just the way of finding out the linked content. You'll have to write some code to update the links by figuring out what part of the page is linking to the content and updating. If links are ContentReferences they are fairly easy but if they are XHtmlStrings you'll need to loop through the fragments of the property and update any fragments that are links to your target page.

Apr 09, 2021 11:57

OK I see, thanks! Yes, we are already aware of the links but need any assistance or guidance on how to update these links.

Apr 09, 2021 12:34
Vote: here are examples of working with url fragments with the XHtmlString property. You just need to loop through them, check if they are a url fragment and point to your link that's changed. Then modify it by creating an internal link to your new content. I don't have any time at the moment to create any code, apologies

You should be able to use ServiceLocator.Current.GetInstance<ContentFragmentFactory>() .CreateContentFragment(block.ContentLink, block.ContentGuid, null); to create the page link I think. But this is off the top of my head with a little google to refresh my memory

Edited, Apr 09, 2021 12:37

Thanks, Scott! That helped internally to discuss the requirements of this project. I will update the thread if there are any changes/progression.

Apr 21, 2021 7:31
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.