News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Converting links embedded into posts

Started by Raptus, October 09, 2005, 10:26:22 AM

Previous topic - Next topic

Raptus

Hello, I succesfully converted a phpBB Forum into SMF 1.0.5, and because of the different URL scheme this makes all links embedded into posts linking between different topics broken. I have partially fixed it now, needing help on a last issue.

I changed to a new domain, too, so I first ran the following SQL query to convert all links to the new domain:

UPDATE smf_messages SET body = REPLACE(body, 'www.olddomain.com/forum', 'forum.newdomain.com');

phpBB uses a URL scheme like viewtopic.php?=topicid while SMFs is like index.php?topic=topicid, so I used:

UPDATE smf_messages SET body = REPLACE(body, 'forum.newdomain.com/viewtopic.php?t=', 'forum.newdomain.com/index.php?topic=');

Additionally I left a php script at the original location which redirects the browser to the new domain and correct topic in case someone follows an external, outdated link.

The remaining problem is that in phpBB you can have links pointing to specific posts only, (viewtopic.php?p=2345), but SMF requires the link to contain topicid + postid (index.php?topic=123.msg2345#msg2345), so I cannot convert them with a (simple) query/script. A conversion script would need to do a DB lookup to check to which topicid a certain postid belongs to and add the missing ?topic=topicid to the URL string.

Any suggestions?
Thanx in advance.

Oldiesmann

Well, your best bet for now would be to do the following:

1. Run this query in phpMyAdmin:

UPDATE smf_messages SET body = REPLACE(body, 'www.olddomain.com/viewtopic.php?p=', 'forum.newdomain.com/viewtopic.php?p=');

Then, put this in a file, save it as viewtopic.php and upload it to your SMF directory:

<?php
include_once('SSI.php');
if(isset(
$_REQUEST['p']))
{
    
$query db_query("SELECT ID_TOPIC FROM {$db_prefix}messages WHERE ID_MSG = '$_REQUEST[p]'"__FILE____LINE__);
    
$topic mysql_result($query0);
    
header('Location: http://forum.newdomain.com/index.php?topic=' $topic '.msg' $_REQUEST['p'] . '#msg' $_REQUEST['p']);
}
?>


That's about the easiest way to do it.
Michael Eshom
Christian Metal Fans

Raptus

Hey, thanks a lot, worked like a charm  :)

HWB

I have also tried that code and being that my databases prefix is now phpbb2 it did not work.

Oldiesmann

So change the database prefix to phpbb2_ in that first query...
Michael Eshom
Christian Metal Fans

KB

Hey Oldiesman....this is probably one of those stupid questions but....

Would the above query and php file method work for links to internal boards (links contained in older posts of course) or would you have to run separate queries/files for links like "?board=" or "?action=" ???

Or is it possible to begin with?

Im in the process of changing to bluehost and my "old" domain will have to be an "add on" domain to the one Ive just registered with them as primary....thus my file structure is now messed up and Ive got broken links all over the place!!

Thanks!

ormuz

Is this solution still working?

Quote from: Oldiesmann on October 11, 2005, 01:35:47 PM
Well, your best bet for now would be to do the following:

1. Run this query in phpMyAdmin:

UPDATE smf_messages SET body = REPLACE(body, 'www.olddomain.com/viewtopic.php?p=', 'forum.newdomain.com/viewtopic.php?p=');

Then, put this in a file, save it as viewtopic.php and upload it to your SMF directory:

<?php
include_once('SSI.php');
if(isset(
$_REQUEST['p']))
{
    
$query db_query("SELECT ID_TOPIC FROM {$db_prefix}messages WHERE ID_MSG = '$_REQUEST[p]'"__FILE____LINE__);
    
$topic mysql_result($query0);
    
header('Location: http://forum.newdomain.com/index.php?topic=' $topic '.msg' $_REQUEST['p'] . '#msg' $_REQUEST['p']);
}
?>


That's about the easiest way to do it.


Advertisement: