1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

phpBB3 SEO - redirect to xenForo

Discussion in 'XenForo Pre-Sales Questions' started by Case, Sep 18, 2012.

  1. Case

    Case Active 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
     
    R_A likes this.
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I don't think I have seen those SEO URLs from phpBB before. You will need some custom rewrite rules for this. I can help with this but first I need you to enter your forum name (Case) on this page so I know you are licensed:

    http://xenforo.com/customers/forum-users
     
  3. Case

    Case Active Member

    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.
     
  4. Arty

    Arty Well-Known Member

    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.
     
    Brandon Sheley and Akela like this.
  5. Case

    Case Active Member

    Great stuff, thanks Arty. It's you that's got me over here from artodia.com, asking questions! ha, cheers.
     
    M@rc likes this.
  6. Akela

    Akela Active Member

    I am also looking to do a phpBB SEO redirect to XF.

    Case, have you tried out Arty's advice?
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    If you can provide examples of old and new URLs then I can make some rewriterules for you. Also, did you enable the import option to preserve the source ids or not?
     
    Akela likes this.
  8. Freezer

    Freezer Member

    me too
     
  9. Case

    Case Active Member

    Yep, worked fine.
     
    Brandon Sheley and Akela like this.
  10. Akela

    Akela Active Member

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

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

    Would not enabling them cause too much trouble? I was hoping to "reset" the forum/topic numbering.

    Thank you for all your help, Jake.
     
  11. Akela

    Akela Active Member

    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?
     
    Brandon Sheley likes this.
  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Akela likes this.
  13. Akela

    Akela Active Member

    But this doesn't work for the silly phpBB SEO URLs. :(
    I will try Arty's advice...
     
  14. ReneHermi

    ReneHermi Member

    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($url01);
      
        
    /* 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_pagecount($url_page)-21);
            
    $typestring_check $typestring[0];

            
    //echo $url ."<br>";
            //echo $typestring_check . "<br>";
            //echo substr($typestring_check, 0,1) . "<br>";
            
    $type substr($typestring_check0,1);
            
    //echo $type . "<br>";
            //echo $type;
            // if last string is int, its paginated
            
    $id intval(substr($typestring_check1));
            
    $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($url01);
            
    $id substr ($url1);
          
            
    //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');
     

Share This Page