The rich text editor within SharePoint will often cause some problems. Except the fact that the created HTML code isn’t always that neat, it is also nearly impossible to use relative paths in your links or images since it will always include the domain you’re currently on in your link. This of course is really annoying, especially when you have a separate domain for editing your content.

However, a workaround is possible which solves your problem. With the help of JavaScript it is possible to change the value of all links on your page. By making sure this piece of JavaScript is included on every page you will never have the problem of accidently creating dead links anymore.

JQuery is a very popular JavaScript framework which is already installed on a lot of sites. Most of the time it makes JavaScript scripting a lot easier and less time consuming. You can use the next piece of script to change all links and images so that the right domain name is being set.

[javascript]

if (document.domain == ‘www.publicurl.com’)
{
$("a[href^=’https://www.contenturl.com’]") .each(function()
{
this.href = this.href.replace(/^https:\/\/www.\.contenturl\.com/, "http://www.publicurl.com");
});
$("img[src^=’https://www.contenturl.com’]") .each(function()
{
this.src = this.src.replace(/^https:\/\/www.\.contenturl\.com/, "http://www.publicurl.com");
});
}
[/javascript]

In the first line:
if (document.domain == ‘www.publicurl.com’)
a check is being done to make sure we are on the public domain at the moment. You don’t want the links to be changed when you are editing the content.
Next, all links are being searched which contain the value “https://www.contenturl.com”. After that a function is begin executed which changes the href of the link from “https://www.contenturl.com” to “http://www.publicurl.com”.

Exactly the same is being done for all images on the site where the “src” of all the “img” tags are being altered.

If JQuery is not already installed and difficult to install it is also possible to use ‘normal’ javascript for this. In this case it isn’t even that much more work to write.

[javascript]

if (document.domain == ‘www.publicurl.com’)
{
for (i=0; i < document.links.length; i++)
{
document.links[i].href = document.links[i].href.replace("https://www.contenturl.com",";http://www.publicurl.com");
}
for (i=0; i < document.images.length; i++)
{
document.images[i].src = document.images[i].src.replace("https://www.contenturl.com","http://www.publicurl.com");
}
}
[/javascript]

This does exactly the same as the script above. It will find all links and images that contain “https://www.contenturl.com” and replaces this with “http://www.publicurl.com”.