Resource icon

Unmaintained phpbb3 redirection Script SEO URLs Apache & Nginx 2013-09-14

No permission to download
Hi there,

use this script to redirect all your old SEO URLS from your phpb3 forum to your new XenForo installation. (Only working for posts, threads and forum links, not for member urls or any other sitelinks)

This script is originally by by @Arty. I modified it 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 in your 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 is page 2;)

Otherwise Google follows the redirection but does not find the expected content on the site because the pagination would be wrong.

Hope it´s helpful for you.
Btw. It´s quick `n dirty but 100% working for me!

Edit 14.09.2013: Change the script to use nginx instead Apache

Installation for Apache webserver:

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 the following code in it:

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');

Copy the htmlp.php into the root of your phpbb3 installation.

Restart/reload your webserver.
Done!

Installation for NGINX webserver:

In your nginx.conf within the location {} block add:
rewrite ^/(.*)\.html$ http://www.yourdomain.com/forum/html.php?orig_uri=$1 last;


That will redirect all *.html links to html.php=?*

Then create html.php, put the followwing code in it*:
*Rewrite the url´s in the script to your needs

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));*/
    $url = explode('/', $_GET['orig_uri']);
    $url = explode('.', array_pop($url));
    //echo $url;
    //echo $_SERVER['HTTP_REFERER'];
    //echo $_SERVER['REQUEST_URI'];
    //echo $_SERVER['REDIRECT_URI'];
    //echo array_pop($url);
    //exit;
    /*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['HTTP_REFERER']);
        $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('http://www.xsimulator.net/community/index.php?threads/' . $id . '/'); //redirect to first page
                }else{
                phpbb_redirect('http://www.xsimulator.net/community/index.php?threads/' . $id . '/page-' . $page); //redirect to paginated page
                }
            case 'f':
                phpbb_redirect('http://www.xsimulator.net/community/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('http://www.xsimulator.net/community/index.php?threads/' . $id . '/');
       
            case 'f':
                phpbb_redirect('http://www.xsimulator.net/community/index.php?forums/' . $id . '/');
        }
            phpbb_redirect('http://www.xsimulator.net/community/');

    }
}
redirect_html();
include('index.php');

Copy the htmlp.php into the root of your phpbb3 installation.

Restart/reload your webserver.
Done!
Author
ReneHermi
Downloads
56
Views
2,678
First release
Last update

Ratings

0.00 star(s) 0 ratings
Top Bottom