View Full Version : Automated redirect for old post/thread links
Richard
August 16th, 2008, 07:32 PM
Folks,
Okay I have written some php code to automagically redirect old forum threads from shrapnelcommunity to the correct thread on forum.shrapnelgames.com. Essentially what I did when we migrated is I stored off the referential ID links between the following items between the new and old boards:
Users
Posts
Threads
Attachments
Polls
My plan is to use this data to one by one put in code to redirect (via the 404 call from apache) any incoming link for the above items to the new links in the new forum. This will resolve any old links in the forums and will also, over time, replace bad links on search engines.
So far I have gotten this to work for threads and am working ont he other items.
What I need is first off people to test that this works for threads. Keep in mind that means links to old threads, not individual posts. What I also need is links to some of the other items listed above so I have a testbed to work from with real links people still can find in old posts/links/etc.
So far I have tested this with the old thread links in Ich's signature and those have worked.
Fyron
August 16th, 2008, 08:12 PM
Out of curiosity, why where the old ID values not simply preserved, and inserted into the vbulletin database? That would have made supporting the old link namespace a simple mod_rewrite rule.
Would it be too late to re-import ID values, thus absolving the need for such complex conversion scripts?
Richard
August 16th, 2008, 08:18 PM
Out of curiosity, why where the old ID values not simply preserved, and inserted into the vbulletin database? That would have made supporting the old link namespace a simple mod_rewrite rule.
The vb import process tries to do things in a very clean way and because of that assigns a new post id/thread id starting at zero. It does preserve a concept of an import ID. I had written something to update all of the postID/threadID's to the old numbers but the one sticking point was threaded mode. Due to the way the parent/child post setup in vb works there was no easy way via sql to update the posts without breaking the parent posts used for threaded mode.
So instead I took some code from the vb import author and extended it a little.
Ballbarian
August 16th, 2008, 08:44 PM
I am not sure if this is what you are looking for, but I pulled these links from one of my threads (http://forum.shrapnelgames.com/showpost.php?p=521919&postcount=1):
THREADS - appear to be working
http://www.shrapnelcommunity.com/threads/showflat.php?Cat=&Number=496176&page=3&view=collapsed&sb=5&o=&fpart=1
http://www.shrapnelcommunity.com/threads/showflat.php?Cat=&Board=d3smm&Number=528292
FILES - not found
http://www.shrapnelcommunity.com/threads/download.php?Number=580660
http://www.shrapnelcommunity.com/threads/download.php?Number=585712
http://www.shrapnelcommunity.com/threads/download.php?Number=591882
http://www.shrapnelcommunity.com/threads/download.php?Number=592318
http://www.shrapnelcommunity.com/threads/download.php?Number=614035
http://www.shrapnelcommunity.com/threads/download.php?Number=629537
http://www.shrapnelcommunity.com/threads/download.php?Number=632163
Ballbarian
August 16th, 2008, 08:49 PM
This old image link is not working either:
http://www.shrapnelcommunity.com/threads/uploads/465573-AomOrc3.JPG
Edit:
And here is an old link that used to go to the dom3 forums that gives me a permissions error instead of the page not found:
http://www.shrapnelcommunity.com/threads/postlist.php?Cat=&Board=dom3
vfb
August 16th, 2008, 08:58 PM
Sounds like a great feature!
But my old embedded links do not seem to be working either, eg:
http://www.shrapnelcommunity.com/threads/showflat.php?Number=595147&bodyprev=#Post595147
Even this does not work:
http://www.shrapnelcommunity.com/threads/showflat.php?Number=595147
Is it because I'm not linking to the top thread?
Mindi
August 16th, 2008, 09:02 PM
I don't think he's gotten to the individual post redirects yet. Right now he's working on thread and trying to confirm it's working. But he will need other links to verify when he gets to the posts, so I am sure your links will be helpful.
Ballbarian
August 16th, 2008, 09:02 PM
I think Richard must be making changes, because my threads don't redirect either vfb (but they did earlier). Otherwise, I imagine that your 2nd method would have worked.
Edit:
Ah, Mindi. You are too fast!
Richard
August 17th, 2008, 05:21 PM
I am not sure if this is what you are looking for, but I pulled these links from one of my threads (http://forum.shrapnelgames.com/showpost.php?p=521919&postcount=1):
THREADS - appear to be working
http://www.shrapnelcommunity.com/threads/showflat.php?Cat=&Number=496176&page=3&view=collapsed&sb=5&o=&fpart=1
http://www.shrapnelcommunity.com/threads/showflat.php?Cat=&Board=d3smm&Number=528292
FILES - not found
http://www.shrapnelcommunity.com/threads/download.php?Number=580660
http://www.shrapnelcommunity.com/threads/download.php?Number=585712
http://www.shrapnelcommunity.com/threads/download.php?Number=591882
http://www.shrapnelcommunity.com/threads/download.php?Number=592318
http://www.shrapnelcommunity.com/threads/download.php?Number=614035
http://www.shrapnelcommunity.com/threads/download.php?Number=629537
http://www.shrapnelcommunity.com/threads/download.php?Number=632163
Okay all of these should work now. Let me know...
Richard
August 17th, 2008, 05:34 PM
This old image link is not working either:
http://www.shrapnelcommunity.com/threads/uploads/465573-AomOrc3.JPG
Edit:
And here is an old link that used to go to the dom3 forums that gives me a permissions error instead of the page not found:
http://www.shrapnelcommunity.com/threads/postlist.php?Cat=&Board=dom3
Okay all old uploads should redirect now so #1 should work. For #2 what I did is anything with postlist.php goes to a generic page on the new forum. Since we have no way to determine what the old crappy (editorial comment on UBB software :)) word based forum names to the new forum numbers we can't do a better automated solution...
Richard
August 17th, 2008, 05:50 PM
Sounds like a great feature!
But my old embedded links do not seem to be working either, eg:
http://www.shrapnelcommunity.com/threads/showflat.php?Number=595147&bodyprev=#Post595147
Even this does not work:
http://www.shrapnelcommunity.com/threads/showflat.php?Number=595147
Is it because I'm not linking to the top thread?
Okay so the problem here is the way UBB handled things. The problem is they used the same script to refer to threads and posts without an easy way to know via URI string which they were doing. So for Balbarians posts above they work because there is a reference to the thread. For your's it won't work because your referring to showflat to a post, not a threadid. Posts are supposed to use a different script name (I think it's showthreaded). I am going to on individual posts next but a direct link to a post using showflat is just going to be broken.
Ballbarian
August 17th, 2008, 05:55 PM
Okay all of these should work now. Let me know...
Great! :up:
All appear to be working now with one exception:
http://www.shrapnelcommunity.com/threads/showflat.php?Cat=&Board=d3smm&Number=528292
That old thread link was working with some of your changes (earlier), but now goes to the 404 page.
Richard
August 17th, 2008, 06:26 PM
Great! :up:
All appear to be working now with one exception:
http://www.shrapnelcommunity.com/threads/showflat.php?Cat=&Board=d3smm&Number=528292
That old thread link was working with some of your changes (earlier), but now goes to the 404 page.
Okay this one may be able to be fixed but I am not sure. The problem is most incoming links have an & after the post number and the redirect is looking for that. These types of url's don't have an & at the end so it's confused :). Let me think on that one...
lch
August 18th, 2008, 10:26 AM
Richard, thanks for looking into this. I'd recommend that you create substitutes for the old showflat.php, shownested.php etc. scripts instead of abusing 404 error pages for this.
I'll drop some PHP code here which I have been using for some projects myself. First, a replacement for PHP's parse_url (http://php.net/parse_url) function:
// returns an array with the following elements defined in it:
// scheme://username:password@host:port/path?query#fragment
// this function is more robust than parse_url
function parseUrl($url) {
$r = '!(?:(?<scheme>\w+)://)?(?:(?<username>\w+)\:(?<password>\w+)@)?(?<host>[^/:]+)?';
$r .= '(?:\:(?<port>\d*))?(?<path>[^#?]+)?(?:\?(?<query>[^#]+))?(?:#(?<fragment>.+$))?!i';
preg_match($r, $url, $out);
# for ($i = 0; $i < 9; ++$i)
# unset($out[$i]);
return $out;
} then one which does the reverse: // inverse function to parseUrl
function glueUrl($parsed)
{
if (!is_array($parsed)) return false;
$uri = strlen($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '' : '//') : '';
$uri .= strlen($parsed['user']) ? $parsed['user'].(strlen($parsed['pass']) ? ':'.$parsed['pass'] : '').'@' : '';
$uri .= strlen($parsed['host']) ? $parsed['host'] : '';
$uri .= strlen($parsed['port']) ? ':'.$parsed['port'] : '';
if (strlen($parsed['path'])) {
$uri .= ($parsed['path'][0] == '/') ? $parsed['path'] : ('/'.$parsed['path']);
}
$uri .= strlen($parsed['query']) ? '?'.$parsed['query'] : '';
$uri .= strlen($parsed['fragment']) ? '#'.$parsed['fragment'] : '';
return $uri;
} and finally something which uses both to merge a given URL with a query string, which shows how they can be used: // merges given URL with the specified query string
function MergeQueryStrings($url, $query) {
$parsed = parseUrl($url);
parse_str($query, $addq);
parse_str($parsed['query'], $oldq);
$newq = array_merge($oldq, $addq);
$parsed['query'] = http_build_query($newq);
return glueUrl($parsed);
}
Maybe it's some help. What you really should make use of is the parse_str (http://php.net/parse_str) function.
lch
September 4th, 2008, 04:41 AM
The link redirections don't seem to work anymore. They did before - so please, get them back unless you plan to batch replace all the old links in the posts and signatures.
vBulletin® v3.8.1, Copyright ©2000-2025, Jelsoft Enterprises Ltd.