Recently I spoke to a client who had recently migrated to EPiServer from another CMS. They'd noticed that the number of internal broken links was going up rather than down after the migration. I thought that this was strange as EPiServer maintains all internal links by reference so if a page is moved in the page tree then it's link is automatically updated.
On further investigation it was noticed that editors were not using the EPiServer "Link properties" window to add links internal in the expected manner. Rather than navigate around the page tree to select the page, they were simply pasting in the public URL. Given that the site contained 1000's of pages I didn't think that was unreasonable as overall it saved editors a lot of time.
For example, if an editor wanted to set the value of a "URL to page/external address" property they could:
- Paste http://www.MySite.com/Level1/Level2/ThePageIWant/ directly into the link
- Open the "Link properties" window
- Click "Page on this Web site"
- Click the "..." button
- Expand "Level1"
- Expand "Level2"
- Select "ThePageIWant"
- Click the "Select" button
- Finally click "OK".
If I was an editor, I know what I'd choose!
I wanted a simple solution that resolved this problem without asking editors to change the way they work. The requirement is pretty simple - If a link in as marked as an external link but looks like an internal link then attempt to convert it to an internal link. This is pretty easy to achieve the functionality with a simple HttpModule that hooks into the SavingPage page event of the Datafactory:
It inspects the values of links held in the PropertyUrl, PropertyXhtmlString and PropertyLinkCollection properties and where appropriate attempts to convert to internal links.
Currently the solution works PropertyUrl, PropertyXhtmlString and PropertyLinkCollection which covers most bases. If you have any custom properties then it'd pretty simple to implement for those too. The module can be plugged in for relatively standard EPiServer sites with no modification. Also it would be simple to convert this to a scheduled job or admin tool to cover content that was published before the module was plugged in.
I’ve not converted this to work on EPiServer 6 yet but it should be a simple change.
There are no code downloads as the module code can simply be copied from the code example above.