1

I moved my server and now Wiki images and links point to the old location. What can I do besides editing every wiki entry?

flag

1 Answer

2

You can use a BugMonkey script (My Settings > Customizations) to automatically correct the links when users visit your pages.

Copy the following code to a new customization, and change the value of oldLocation to the beginning of the URL that you want to replace. This will effectively make all the links relative rather than the full hard-coded URL.

name:          Replace local images and links
description:   Replaces hardcoded references to old server images with an empty string, forcing it to use relative resources.
author:        Ben McCormack
version:       1.2.0.0

js:

function replaceLinks(oldLocation) {
  $('img[src*="' + oldLocation + '"]').each(function() {
    $(this).attr('src',  $(this).attr('src').replace(oldLocation,  ''));
  });
  $('a[href*="'  + oldLocation + '"]').each(function() {
    $(this).attr('href', $(this).attr('href').replace(oldLocation, ''));
  });
}
$(document).ready(function() {
  replaceLinks('http://benm/');
});

This will even fix http links after changing benm to https.

link|flag
1 
I fixed a typo which broke the <img> part. – Michel de Ruiter Sep 10 at 15:21
Thanks for the edit! – Ben McCormack Sep 10 at 15:53

Your Answer

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