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

XF 1.3 URL Redirects not working phpBB to XF

Discussion in 'Installation, Upgrade, and Import Support' started by clove28, Sep 2, 2014.

  1. clove28

    clove28 Active Member

    I am having a problem in creating a url redirect after importing phpbb to xenforo. I tried the scripts available in the resource but none is working. I tried to search Google using the keyword I was ranking at to check but it only shows 404.:(
     
  2. clove28

    clove28 Active Member

    Here is the redirect code I got but I don't know where to put this line..

    in this code..

    Code:
    <?php
    /**
    * phpBB redirection script for XenForo
    *
    * by Simon Tunnat
    */
    
    function redirect($url) {
        header('HTTP/1.1 301 Moved Permanently');
        header('Location: ' . $url);
        exit;
    }
    
    $type = null;
    $page = null;
    $id = null;
    
    if ( isset($_SERVER['REQUEST_URI']) ) {
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $url = explode('.', array_pop($url));
    
        if( $url[0] == 'viewforum' && isset($_GET['f']) ) {
            $type = 'forums';
            $id = intval($_GET['f']);
        } elseif( $url[0] == 'viewtopic' ) {
            if( isset($_GET['p']) ) {
            $type = 'posts';
            $id = intval($_GET['p']);
            } elseif( isset($_GET['t']) ) {
                $type = 'threads';
            $id = intval($_GET['t']);
            }
        } 
    
        if( isset($_GET['start']) ) {
            $postsPerPage = 10;
            $page = intval($_GET['start']) / $postsPerPage;
        }
    }
    
    if( $type !== null && $id !== null && $id !== 0 ) {
        if( $page !== null ) {
            redirect('index.php?' . $type  . '/' . $id . '/page-' . $page);
        } else {
            redirect('index.php?' . $type  . '/' . $id . '/');
        }
    } else {
        redirect('index.php');
    }
    
     
  3. Mike

    Mike XenForo Developer Staff Member

  4. clove28

    clove28 Active Member

    Hi Mike! Thanks for your reply.

    I put this code to my htaccess.txt file

    Code:
    #<IfModule mod_security.c>
    #    SecFilterEngine Off
    #    SecFilterScanPOST Off
    #</IfModule>
    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 500 default
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.([^.]+)$
        RewriteRule ^(.*)$ http://%1.%2/$1 [R=301,L]
        #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
        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]
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    </IfModule>
    Do I still need to put this code?

    Code:
    define('IMPORT_LOG_TABLE', 'import_log_old_forum');>
    And once I put those code will there be an immediate effect or I need to wait for hours or day to see it? I'm really new to all these redirection so I couldn't understand very well. Thanks!:)
     
  5. clove28

    clove28 Active Member

  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

Share This Page