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;
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
You can use Shortcuts. Create a shortcut on Old page that redirects the user to the new page.
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.
You can use the ContentSoftLinkRepository as described here https://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2019/4/finding-all-content-a-page-is-referencing/ 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.
Thanks, I will check that out...
This would be for static HTML or only those through the page selection tool?
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)
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.
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.
OK I see, thanks! Yes, we are already aware of the links but need any assistance or guidance on how to update these links.
https://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2018/6/xhtmlstring-tohtmlstring-and-internal-links-episerver-11-8-1/ https://world.episerver.com/blogs/Linda-Mohacsi/Dates/2018/2/modify-the-remaining-url-value-on-properties-of-type-linkitem-and-url/ 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
Thanks, Scott! That helped internally to discuss the requirements of this project. I will update the thread if there are any changes/progression.