News:

Wondering if this will always be free?  See why free is better.

Main Menu

Automatic redirection script for YaBB to SMF

Started by TAY, April 16, 2006, 04:54:57 PM

Previous topic - Next topic

TAY

I upgraded my old YaBB forum (YaBB 1 Gold - SP 1.1) to SMF (1.0.7), using the conversion script obtained here at SMF (yabb_to_smf.php). The URLs for the new SMF pages are different from the old YaBB pages, and I didn't want to have links to YaBB threads (topics) broken (eg. from searches, other sites) so I came up with a redirect script which automatically sends the browser from a YaBB thread URL to the corresponding SMF thread URL. This redirect works great (4000 threads in YaBB forum, haven't been able to make it throw an error) and so I thought I would share the info about how to do it. I haven't looked at any other conversion scripts (eg. phpBB to SMF) but I would guess that this approach is generalizable.

Here's the basic problem: URLs for the same thread (topic) in the two forums (these are not functional URLs):
YaBB: hxxp:www.mysite.com/cgi-bin/yabb/YaBB.pl?board=snakes;action=display;num=1121829556 [nonactive]
SMF: hxxp:www.mysite.com/smf/reptiles/index.php?topic=3052 [nonactive]

What is needed is a list with a one to one correspondence between the YaBB "num=xxxxxxxxxx" value and the SMF "topic=xxxx" value (note that the latter can be any number of digits, not just four). It turns out the conversion script creates a temporary column containing the YaBB values in one of the SMF database tables, and these are paired with the corresponding SMF values in the table. The script normally deletes (drops) the YaBB value column, but by deleting eight lines of code from the conversion script the YaBB values column can be retained.

So, here are the basic parts involved in getting this redirect to work (details below). This all assumes that an empty (new install) SMF forum has been installed and is functional.
1) Modify the conversion script (yabb_to_smf.php) so that the temporary column is not dropped.
2) Run the modified conversion script just as you would run the unmodified script - see instructions that come with the original script (this populates the SMF database with info from the old YaBB forum).
3) Upload the redirect script into the YaBB directory (after specifics are added to it - see below).
4) Upload an .htaccess file into the YaBB directory which uses RewriteEngine to send any browser request into that directory to the redirect script (see below).
5) Test it! I did this by making a bunch of bookmarks for YaBB threads, then using them to make sure that I was redirected to the corresponding SMF thread. If you can easily find links to your forum's threads using Google, then that is another way to test. To be able to freely test, I made a copy of my YaBB forum, then ran the conversion from that copy. That way I could drop the redirect script and .htaccess file into the YaBB copy directory and test without disrupting the original YaBB forum (ie. I didn't have to shut the original down to test the redirect script). Once I was sure that everything would work as hoped, I shut down the real YaBB forum and ran the conversion on it, then dropped the redirect script and .htaccess file into its directory. Don't upload the .htaccess file into the real YaBB directory until you are ready for all of your forum's users to have access to the new SMF forum.

Here are the details:

Modify the conversion script: the conversion script (yabb_to_smf.php) needs to be modified to retain the "tempID" column in the "_topics" table in the SMF database. In the conversion script tagged "Software Version SMF 1.0.5", this was done by deleting lines 1812-1819 in the script. Here's the code that needs to be deleted:

if ($_REQUEST['start'] <= 0)
{
mysql_query("
ALTER TABLE {$to_prefix}topics
DROP tempID");

pastTime(1);
}

Now when the conversion script is run, there will be an additional column in the SMF database table "_topics" which is called "tempID". This column contains the YaBB "num=xxxxxxxxxx" value. The table also contains a column called "ID_TOPIC" which holds the SMF "topic=xxxx" value for each corresponding thread. So there's the list with a one to one correspondence. It should be noted that if a column called "tempID" already exists in the "_topics" table, then when the conversion script is run the conversion will fail. So if you run a test of the conversion, you need to be sure to delete the "tempID" column before running the conversion script again. Another note: for the security of my new SMF database, I copied the "_topics" table into a new database to be used solely by the redirect script; this would seem like a good idea in general.

Redirect script: Here's the complete conversion script, with generics that would have to be replaced with your details:

<?PHP
$querystr = $_SERVER['QUERY_STRING'];
$querystr2 = str_replace(";", "&", $querystr);
parse_str($querystr2);
if ($num == '')
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.mysite.com/smfdirectory/index.php');
}
elseif (ctype_digit($num))
{
mysql_connect("databaseHOSTNAME", "databaseUSERNAME", "databasePASSWORD") or die(mysql_error());
mysql_select_db("databaseNAME") or die(mysql_error());
$smf = mysql_query("SELECT ID_TOPIC FROM smfprefix_topics WHERE tempID = $num");
$row = mysql_fetch_array( $smf );
$topic = $row['ID_TOPIC'];
if ($topic !== null)
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.mysite.com/smfdirectory/index.php?topic='.$topic);
}
else
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.mysite.com/smfdirectory/index.php');
}
}
else
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.mysite.com/smfdirectory/index.php');
}
?>

You can name this redirect script anything you want, but that same name must be used in the .htaccess file (see below).

The generics that need to be replaced with your specifics are:
-- hxxp:www.mysite.com/smfdirectory/index.php [nonactive] === the complete URL to your SMF install's index page (4 places).
-- databaseHOSTNAME, databaseUSERNAME, databasePASSWORD, databaseNAME === your database's specifics (1 place each).
-- smfprefix_topics === the prefix used for all tables in your SMF database, followed by "_topics" (1 place). If your SMF prefix is "kool", then this value would be "kool_topics".

This redirect script strips out the 10 digit YaBB "num=xxxxxxxxxx" value from the incoming URL and uses it to query the database "_topics" table. If a match is found, then the SMF "topic=xxxx" value is returned and used to form the URL for the corresponding SMF thread, to which the browser is redirected. There are conditionals in the script that send any non-valid YaBB URL to the main index page of the SMF forum. YaBB URLs which are valid but not for a thread (eg. for a board index, search, member list, etc) are also screened out and redirected to the SMF index page.  The user sees none of this - the redirection is very quick.

.htaccess file: This simply redirects any browser request into the YaBB directory to the redirect script. Here's the code for a redirect script named "redirect_to_smf.php":

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.*)$ redirect_to_smf.php


Hope this is useful.
TAY

vls


JBlaze

Quote from: vls on March 12, 2009, 04:44:31 PM
Hi mate, many thanks.

Do you have any insight on this: http://www.simplemachines.org/community/index.php?topic=122338.0

Thank you.

This converter basically will convert a YaBB forum to SMF without losing most data. If you follow the simpl instructions provided, there should be no problems.

I'm assuming you are trying to convert from a YaBB forum?
Jason Clemons
Former Team Member 2009 - 2012

Advertisement: