phpBB3 SEO - redirect to xenForo

Case

Well-known member
Hi guys

Thinking of converting my phpBB3 site to xenForo. I currently run phpBB3 with the SEO mod so my site URL's look like this...

forum/topic-title-t1234.html
forum/forum-name-f1.html

Any idea of the changes I need to make to my .htaccess file to get everything redirecting to the correct xenForo equivalent URL?

I did see this thread http://xenforo.com/community/threads/phpbb3-redirection.28094/ but I think that's just for the standard phpBB3 URL's.

Thanks
 
OK, thanks Jake. When I've grabbed a license, I'll post in there.

Just doing some research first to see how easy the switch will be. All looking good so far. Obviously this is a big concern, need to make sure all current content isn't lost in the search engines.

Cheers.
 
In .htaccess find
Code:
RewriteRule ^.*$ index.php [NC,L]
and add before it:
Code:
RewriteRule ^(.*)\.html html.php [NC,L]
That will redirect all .html links to html.php

Then create html.php, put something like this in it:
Code:
<?php
 
function phpbb_redirect($url)
{
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: ' . $url);
    exit;
}

function redirect_html()
{
    if (!isset($_SERVER['REQUEST_URI']))
    {
        return;
    }
    $url = explode('/', $_SERVER['REQUEST_URI']);
    $url = explode('.', array_pop($url));
    if (array_pop($url) != 'html')
    {
        return;
    }
    $url = explode('-', array_pop($url));

    $url = array_pop($url);
    $type = substr($url, 0, 1);
    $id = intval(substr($url, 1));
    if (!$id) return;
    
    switch ($type)
    {
        case 't':
            phpbb_redirect('index.php?threads/' . $id . '/');
        case 'f':
            phpbb_redirect('index.php?forums/' . $id . '/');
    }
}

redirect_html();
include('index.php');
I haven't tested that code.
 
If you can provide examples of old and new URLs then I can make some rewriterules for you.
Old: debate-forum-f21/race-t2849-20.html

I haven't done the import yet (scheduled in 9 hours), so I am not sure.

Also, did you enable the import option to preserve the source ids or not?
Would not enabling them cause too much trouble? I was hoping to "reset" the forum/topic numbering.

Thank you for all your help, Jake.
 
OK, I completed the transfer with the preserved source IDs.

I have this bit in my htaccess, taking care of the regular phpBB URL redirects:
Code:
        RewriteCond %{QUERY_STRING} (^|&)t=([0-9]+)(&|$) [NC]
        RewriteRule ^viewtopic\.php$ /threads/%2? [L,R=301,NC]
        RewriteCond %{QUERY_STRING} (^|&)p=([0-9]+)(&|$) [NC]
        RewriteRule ^viewtopic\.php$ /posts/%2? [L,R=301,NC]
        RewriteCond %{QUERY_STRING} f=(\d+)$ [NC]
        RewriteRule ^viewforum\.php$ /forums/%1 [L,R=301,NC]

Old phpBB SEO URLs:
debate-forum-f21/
debate-forum-f21/race-t2849-20.html

New XF URLs:
forums/debate-forum.21/
threads/race.2849/

My brain is a bit fried after sitting on the transfer for 5 hours. Is Arty's suggestion the best option in my case?
 
Hi there,

i modified the script by @Arty to fit the needs for proper redirection of the paginated pages. The main problem is that XenForo uses 20 posts per page where phpbb 3 shows only 10. That means a phpbb Url like

building-a-proper-motion-seat-base-for-scn5-s-t2216-20.html
which is the page 3 of the phpbb3 forum
must be translated to a XenForo URL like:
building-a-proper-motion-seat-base-for-scn5s.2216/page-2

Notice, that the XenForo link must be page 2;)

Hope you it helps someone with similar problems.
Btw. It´s quick `n dirty but working!

PHP:
<?php
function phpbb_redirect($url)
{
  
    //exit;
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: ' . $url);
    exit;
}

function redirect_html()
{
    if (!isset($_SERVER['REQUEST_URI']))
    {
        return;
    }
    $url = explode('/', $_SERVER['REQUEST_URI']);
    $url = explode('.', array_pop($url));
    if (array_pop($url) != 'html')
    {
        return;
    }
    $url = explode('-', array_pop($url));

    $url = array_pop($url);
    $type = substr($url, 0, 1);
  
    /* get the next to last string */
    if (is_numeric($type) == true && $type) { // There is pagination like are-you-a-new-member-introduce-here-t1737-10.html
        $url_page = explode('/', $_SERVER['REQUEST_URI']);
        $url_page = explode('-', array_pop($url_page));
      
        $typestring = array_slice($url_page, count($url_page)-2, 1);
        $typestring_check = $typestring[0];

        //echo $url ."<br>";
        //echo $typestring_check . "<br>";
        //echo substr($typestring_check, 0,1) . "<br>";
        $type = substr($typestring_check, 0,1);
        //echo $type . "<br>";
        //echo $type;
        // if last string is int, its paginated
        $id = intval(substr($typestring_check, 1));
        $page = $url/10; //Division durch 10
      
        //echo $page;
        switch ($type)
        {  
            case 't':
                if ($id == 1){
                phpbb_redirect('index.php?threads/' . $id . '/'); //redirect to first page
                }else{
                phpbb_redirect('index.php?threads/' . $id . '/page-' . $page); //redirect to paginated page
                }
            case 'f':
                phpbb_redirect('index.php?forums/' . $id . '/');
        }
    } else { // No pagination (Maybe first page of the thread) like like are-you-a-new-member-introduce-here-t1737.html
  
        $type = substr($url, 0, 1);
        $id = substr ($url, 1);
      
        //echo $id . "<br>";
        //echo $type;
        switch ($type)
        {  
            case 't':
                phpbb_redirect('index.php?threads/' . $id . '/');
              
            case 'f':
                phpbb_redirect('index.php?forums/' . $id . '/');
        }
  
    }
}
redirect_html();
include('index.php');
 
hmmm 5 years later... :unsure:

I think you made a typo here:
switch ($type) { case 't': if ($id == 1){ phpbb_redirect('index.php?threads/' . $id . '/');
it should be $page instead of $id as you are checking if there is a page.
Although forums can be paginated, so I am looking at it tight now... o_O
PHP:
case 't':
if ($page == 1){
                phpbb_redirect('index.php?threads/' . $id . '/'); //redirect to first page
            }else{
                phpbb_redirect('index.php?threads/' . $id . '/page-' . $page); //redirect to paginated page
            }
break;
        case 'f':
            if ($page == 1){
                phpbb_redirect('index.php?forums/' . $id . '/'); //redirect to first page
            }else{
                phpbb_redirect('index.php?forums/' . $id . '/page-' . $page); //redirect to paginated page
            }
break;
 
Last edited:
Back
Top Bottom