MyBB Community Forums

Full Version: How To redirect old phpbb links and page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello;
you will find here the way to redirect old phpbb links and pages and forums
Thanks to:
-frostschutz
-Dylan M.

this tutorial can have some bugs !!! so help us to fix and generalise it ...

before you do the merge you have to do somes modifications

in merge/index.php find and remove :
    delete_import_fields(); 

now you can converge ...

then create 2 files
viewtopic.php :
<?php
define("IN_MYBB", 1);
define("NO_ONLINE", 1);
require("global.php");

// Did we get an old thread id?
if($mybb->input['t'])
{
    // See if we can get a new one.
    $import_tid = intval($mybb->input['t']);
    $query = $db->simple_select("threads", "tid", "import_tid=${import_tid}");
    $result = $db->fetch_array($query);

    if($result)
    {
        // Redirect to the new thread URL...
        header("Location: ${settings['bburl']}/".get_thread_link($result['tid']), true, 301);
        exit;
    }
}

// By default, redirect back to index.
header("Location: ${settings['bburl']}", true, 301);
exit;
?>

viewforum.php
<?php
define("IN_MYBB", 1);
define("NO_ONLINE", 1);
require("global.php");

// Did we get an old thread id?
if($mybb->input['f'])
{
    // See if we can get a new one.
    $import_fid = intval($mybb->input['f']);
    $query = $db->simple_select("forums", "fid", "import_fid=${import_fid}");
    $result = $db->fetch_array($query);

    if($result)
    {
        // Redirect to the new thread URL...
        header("Location: ${settings['bburl']}/".get_forum_link($result['fid']), true, 301);
        exit;
    }
}

// By default, redirect back to index.
header("Location: ${settings['bburl']}", true, 301);
exit;
?>

viewtopic.php
this file get the old ids of the topics and convert them to the new ids of the same topics and create the final url

viewforum.php
same as topicredirect.php for forum instead of topics

and put the following code in you .htaccess
RewriteEngine On
RewriteRule ^topic([0-9]+)\.html$ viewtopic.php?t=$1 [L]
RewriteRule .*\-f([0-9]+)\/.*\-t([0-9]+)\.html$ viewtopic.php?t=$2 [L]
RewriteRule .*\-f([0-9]+)\/$ viewforum.php?f=$1 [L]

this .htaccess is for those who use phpbbseo with phpbb


Thank You !!
Just use input[t] and name the file itself viewtopic.php then you can work without rewrites at all

Otherwise it's just
RewriteRule ^external\.php$ internal.php [L,QSA] to make yoururl/external.php
actually call internal.php instead.
yes very usefull
I think now all urls can be redirect correctly
only urls with this form
with phpbbseo
post7349.html#p7349

or
without phpbbseo
viewtopic.php?f=98&p=7363#p7363

I think that we cant resolve this redirection
because ther is no import_pid in database
(2011-12-26, 05:26 PM)sharingamak Wrote: [ -> ]I think that we cant resolve this redirection
because ther is no import_pid in database

Hi all,

I think I have solved the lack of import_pid. Basically I modified the merge script to add the import_pid column to the posts table.

Modified merge/functions.php to add the import_pid and import_uid colums to the posts table:

     $add_list = array(
          "int" => array(
               "users" => array('import_uid', 'import_usergroup', 'import_displaygroup'),
               "forums" => array('import_fid', 'import_pid'),
               "threads" => array('import_tid', 'import_uid', 'import_poll', 'import_firstpost'),
               "posts" => array('import_pid', 'import_uid'),
               "polls" => array('import_pid', 'import_tid'),
               "usergroups" => array('import_gid'),
               "events" => array('import_eid'),
               "attachments" => array('import_aid'),
          ),

Then modfiied merge/modules/posts.php to comment out the unset of the import_pid / import_uid

          # unset($insert_array['import_pid']);

          # unset($insert_array['import_uid']);

Also added the following code block to viewtopic.php above:

elseif($mybb->input['p'])
{
    // See if we can get a new one.
    $import_pid = intval($mybb->input['p']);
    $query = $db->simple_select("posts", "tid", "import_pid=${import_pid}");
    $result = $db->fetch_array($query);

    if($result)
    {
        // Redirect to the new thread URL...
        header("Location: ${settings['bburl']}/".get_thread_link($result['tid']), true, 301);
        exit;
    }
}

By the way, this code works perfectly for punbb (which I'm using it for) - you just need to use "id" instead of "tid/fid" for the forum/topic id and "pid" instead of "p" as the post id.
This works. As long as you never do another merge. Smile