Redirecting MyBB URL's

m1ne

Well-known member
Hello.

I've not converted my MyBB forum yet, but I know this will be a problem, so I am posting now.
Is there any way to redirect old MyBB url's to XF links? Using htaccess perhaps?
MyBB URL's look like this,

/thread-30028.html
/forum-121.html
/user-2.html

I've got a lot of indexed url's so I hope there's a way to do this.

Thank you.
 
Put these rules at the top of the .htaccess file in the web root for http://mysite.com/

Code:
RewriteEngine On
RewriteRule ^Thread-([^/]+)$ /mybbthreadredir.php?slug=$1 [R=301,L]

And make sure the mybbthreadredir.php file (previously attached) is uploaded to the web root for http://mysite.com/, and that the mybb_google_seo table has been copied to your XF database (as previously mentioned).

I have followed all your instructions.
In .htaccess I have added the code at the top of the .htaccess file and uploaded it in my web root.
I have copied the mybb_google_seo database to the XF database.
I have uploaded the mybbthreadredir.php in the web root (where my forum is located).

What happes is this:
For example if I enter an old link like this: mysite.com/Thread-name-of-thread I get directed to mysite.com/threads/xxx (thread number).

This is very frustrating :( I have tried different links, and I always get this error:

Not Found
The requested URL /threads/124 was not found on this server.

This is my .htaccess file:

Code:
#    Mod_security can interfere with uploading of content such as attachments. If you
#    cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>
RewriteEngine On
RewriteRule ^Thread-([^/]+)$ /mybbthreadredir.php?slug=$1 [R=301,L]
ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default

<IfModule mod_rewrite.c>
    RewriteEngine On

    #    If you are having problems with the rewrite rules, remove the "#" from the
    #    line that begins "RewriteBase" below. You will also have to change the path
    #    of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^Thread-([^/]+)$ /mybbthreadredir.php?slug=$1 [R=301,L]
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>

I have double checked everything.

This is the code in mybbthreadredir.php:
Code:
<?php

$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

####################

// GET DB
$db = XenForo_Application::get('db');

$_REQUEST['slug'] = (isset($_REQUEST['slug']) ? $_REQUEST['slug'] : '');

$id = $db->fetchOne("
    SELECT id
    FROM mybb_google_seo
    WHERE url = ?
    AND active = 1
    AND idtype = 4
", $_REQUEST['slug']);

if ($id)
{
    header ('HTTP/1.1 301 Moved Permanently');
    header ('Location: http://mysite.com/threads/' . $id);
}

Im sorry for tagging you @Brogan, but you seem to be online a lot more often, and I really want to fix this! :)
 
Last edited:
Oh, you aren't using friendly URLs. Edit the mybbthreadredir.php file and change the URL to use index.php:

Rich (BB code):
if ($id)
{
    header ('HTTP/1.1 301 Moved Permanently');
    header ('Location: http://mysite.com/index.php?threads/' . $id);
}
 

Add these rules to the top of the .htaccess file in the /Forums directory:

Code:
RewriteEngine On

RewriteCond %{QUERY_STRING} (^|\?)tid=([0-9]+)&pid=([0-9]+)($|&)
RewriteRule ^showthread\.php$ /community/posts/%3/? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)tid=([0-9]+)($|&)
RewriteRule ^showthread\.php$ /community/threads/%2/? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)action=profile&uid=([0-9]+)($|&)
RewriteRule ^member\.php$ /community/members/%2/? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)fid=([0-9]+)($|&)
RewriteRule ^forumdisplay\.php$ /community/forums/%2/? [R=301,L]
 
Thanks! Is there anywhere you could point me to that explains how the redirect rules work? All explanations I have found so far have been hard to understand and so that in part has meant I have been unable to get a grasp of these rules.
 
How should I do the changing .htaccess :

For example:

MYBB URL was like that : xxx.org/konu-Akiskanlar-Mekanigi-Ders-Notlari-S-Yildiz.html
XenForo URL is like that : xxx.org/threads/akiskanlar-mekanigi-ders-notlari-s-yildiz.19/

Thank you.
 
How should I do the changing .htaccess :

For example:

MYBB URL was like that : xxx.org/konu-Akiskanlar-Mekanigi-Ders-Notlari-S-Yildiz.html
XenForo URL is like that : xxx.org/threads/akiskanlar-mekanigi-ders-notlari-s-yildiz.19/

Thank you.

Copy the mybb_google_seo table from MyBB's database to XF's database.

Upload the script attached in this post to your web root.

Then add these rules to the top of the .htaccess file in your web root:

Code:
RewriteEngine On

RewriteRule ^konu-([^/]+)\.html$ /mybbthreadredir.php?slug=$1 [R=301,L]

That should do it.
 
It works, Thank You.

One more question, Can I do this

RewriteEngine On

RewriteRule ^forum-([^/]+)\.html$ /mybbthreadredir.php?slug=$1 [R=301,L]

for

xxx.org/forum-Makine-Muhendisligi

or how I can do ?
 
It works, Thank You.

One more question, Can I do this

RewriteEngine On

RewriteRule ^forum-([^/]+)\.html$ /mybbthreadredir.php?slug=$1 [R=301,L]

for

xxx.org/forum-Makine-Muhendisligi

or how I can do ?

Upload the script attached in this post to your web root.

Then add these rules to the top of the .htaccess file in your web root:

Code:
RewriteEngine On

RewriteRule ^forum-([^/]+)\.html$ /mybbforumredir.php?slug=$1 [R=301,L]
 

Ok that is different than your original example.

Upload this script to your web root (where XF is):

http://xenforo.com/community/threads/redirecting-mybb-urls.28809/page-2#post-708975

Edit the end of that file to specify your forum URL:

Rich (BB code):
if ($id)
{
	header ('HTTP/1.1 301 Moved Permanently');
	header ('Location: http://cepedit.com/forum/' . $id);
}

Then add these rules to the top of the .htaccess file in your web root:

Code:
RewriteEngine On

RewriteRule ^forum-([^/]+)$ /mybbforumredir.php?slug=$1 [R=301,L]

That should do it.
 
Top Bottom