SMF Support > vBulletin

Aliasing old VB postURLs to SMF URLs

<< < (4/4)

MrMike:
.htaccess is pretty powerful, but there are things it simply cannot do. You might want to think about routing requests to an active page for processing.

Here's something else that might work. This is something I had to do on CODmb.com, a forum for Call of Duty players. It's not an ideal fix, but it works. When we converted the board we didn't want to lose all the current links into the board. So what we did was save the old post/user IDs, detect that pattern, and reroute the request to a php file to build the right URL.
 
The SMF board on CODmb.com was converted from a bespoke message board with a very different database structure. When we converted the posts and topics we saved all the post and topic IDs from the original table and mapped them to the new post and topic IDs in the SMF messages table.

We saved all this stuff in a new table, so we have a table that has the before and after IDs to the posts.
 
 The old board used 2 files named 'view_topic.php' and view_posts.php' to view things. We wrote our own versions of those two files and all they do is look up the old post/topic info, build a new URL for SMF, and send the user to it.
 
 The downside is that those old URLs and the table will persist for years. Even they're aren't valid URLs they still work. Keeping the files and table there is no big deal, but it's clutter. Like I said, it's not a perfect solution, but it works. :)
 
 Perhaps you could do something similar on your site?
 

_saiko:
Thanks.

What I figured is the following:
Since vb doesn't use topic_id in it's URL and uses only the post_id I'll have to get the topic_id.
The smf_messages table contains both topic_id and post_id, I'll use the existing smf database to match the topic_id.

I'll just create a vb2smf_url.php like this:

--- Code: ---<?php

/*
URL Translation 
From:
(topic_id  = 1234 is inside thread_id = 12)
http://www.domain.com/showthread.php?p=1234

To:
http://www.domain.com/index.php?topic=12.msg1234
*/

$qstring = $_SERVER['REQUEST_URI'];

$pattern = '|/showthread\.php\?p=(\d+)|';
preg_match($pattern, $qstring, $matches, PREG_OFFSET_CAPTURE, 3);

$post_id = $matches[1][0];

//connect to db and get topic_id for the read post_id
$db = mysql_connect('DB_ADDRESS','DB_USER','DB_PASS') or die("Database error");
mysql_select_db('DB', $db); 
$topic_id = mysql_query('SELECT id_topic FROM `smf_messages` WHERE id_msg = $post_id');

// make link
$new_url = "http://www.domain.com/index.php?topic=$topic_id.msg$post_id";

header("Location: $new_url");

?>
--- End code ---

Does this make any sense?
I realize this approach makes an additional connection to the database, how can I optimize the procedure so I can benefit from the already connected session?

MrMike:

--- Quote from: _saiko on November 10, 2011, 08:35:41 AM ---Does this make any sense?
I realize this approach makes an additional connection to the database, how can I optimize the procedure so I can benefit from the already connected session?
--- End quote ---

Yep, this is more or less what we did.

As for the extra connection, I wouldn't worry about it. It's unlikely to be an issue unless you have overwhelming traffic.

I'm not sure the sql you showed there is right, however.

Navigation

[0] Message Index

[*] Previous page

Go to full version