Keeping old links alive

Keeping old links alive

As mentioned in the past, I am in the process of rewriting the code of Hive to be compatible with XenForo 2. A task I spent a while on was to make sure old links got redirected properly and to have no broken images in the new version.

I found that there is an official add-on called XenForo Redirects for vBulletin but it falls short of my expectations for a couple of reasons:

  • Links are not rewritten for the official media gallery.
  • Attachment thumbnail links redirect to the full size.
  • My site was located in forums/ and all URLs such as forums/showthread.php are not redirected properly, so it's practically useless.
  • I have many custom URLs aside from that which I need to support anyway.

So I built my own...

To ensure I am not missing anything, I wrote a script to export links from all messages in the xf_post table. The table containing all posts on Hive.

I ran it and piped all the URLs to a file which resulted in a ~25 MB file and many links are duplicates. I wrote a quick script to remove the duplicates which reduced the file to about ~7 MB of links.

Next I wrote a function that for a given link matches it against various patterns and return the link to their new location. Quite quickly I got the file of links down to very few completely garbage links.

This took some amounts of time, but as the owner of a website created in 2004, keeping old references is more important than people might think.