Skip to:
Content
Pages
Categories
Search
Top
Bottom

Redirect for old phpBB to new bbPress on different domain


  • Schoelje
    Participant

    @schoelje

    I’ve successfully imported phpBB data into bbPress. Now, I’d like to redirect URLs like
    http://my_phpbb_domain.com/viewtopic.php?f=1&t=2
    to:
    http://my_wordpress_domain.com/forums/topic/corresponding_topic/

    I’ve search the web and have been experimenting with several solutions but without any luck. Anything I do throws a 404.

    These are some of the links I tried out:

    Rewriting URLs

    Redirection to new bbPress board?

    As you can see, these topics are at least 7 years old. On the other hand, I don’t expect that something has changed on how to write redirects in an htaccess file.

    Does somebody here has some experience with this?

Viewing 12 replies - 1 through 12 (of 12 total)

  • Schoelje
    Participant

    @schoelje

    It took some time to make this topic visible on the forum. So, I’ve solved my own problem.

    Instead of writing an htacces file I chose to write an alternative viewtopic.php script that collects the appropriate new bbPress URL from the database.

    If your new bbPress forum is online, you place the following script in your old phpBB domain and save it as viewtopic.php (exactly where the old viewtopic.php used to be located) and don’t forget to replace the “my_xxxx” values with your information:

    <?php
      // If all else fails, use this url.
      $defaulturl = "http://my_domain/forums/";
      
      // Your new bbPress database credentials.
      $host = "my_host";
      $db = "my_database";
      $dbuser ="my_database_user";
      $userpwd = "my_database_user_password";
      
      // Build the query according to url parameters p or t.
      $query = '';
      if (!empty($_GET['p'])) {
          $query = "SELECT xkcom_posts.guid FROM xkcom_postmeta 
                    INNER JOIN xkcom_posts ON xkcom_posts.ID = xkcom_postmeta.post_id 
                    WHERE xkcom_postmeta.meta_key = '_bbp_old_reply_id' 
                    AND xkcom_postmeta.meta_value = '" . $_GET['p'] . "';";
      }else if (!empty($_GET['t'])) {
          $query = "SELECT xkcom_posts.guid FROM xkcom_postmeta 
                    INNER JOIN xkcom_posts ON xkcom_posts.ID = xkcom_postmeta.post_id 
                    WHERE xkcom_postmeta.meta_key = '_bbp_old_topic_id' 
                    AND xkcom_postmeta.meta_value = '" . $_GET['t'] . "';";
      }
      
      // Set the new url to the default url
      $url = $defaulturl;
      
      // Check if we need to make a database connection.
      if (!empty($query)) {
        // Make a connection
        $mysqli = new mysqli($host, $dbuser, $userpwd, $db);
        
        // Check the connection.
        if (!$mysqli->connect_errno) {
          // Run the query.
          $result = $mysqli->query($query);
          
          // Get the new URL.
          if ($result) {
    	$row = $result->fetch_array(MYSQLI_ASSOC);
    	$guid = trim($row["guid"]);
    	if (!empty($guid)) {
    	  $url = $guid;
    	}
          }
    
          // Free the result set.
          $result->free();
    
          // Close the connection.
          $mysqli->close();
        }
      }
      
      //var_dump($url);
      
      // Write the header.
      header("Location: " . $url, true, 301);
    ?>

    Schoelje
    Participant

    @schoelje

    Note: else if should be elseif.
    It still works, though.

    How do I set this topic to resolved?


    Dan
    Participant

    @hypnoticdan

    @shoelje this worked great for me. Thank you!
    I made a few small tweaks that will make the next person’s set that much easier.

    
    <?php
    include "../wp-config.php";
    
      // If all else fails, use this url.
      $defaulturl = "http://your_domain_goes_here/forums/";
    
      // Build the query according to url parameters p or t.
      $query = '';
      if (!empty($_GET['p'])) {
          $query = "SELECT {$table_prefix}posts.guid FROM {$table_prefix}postmeta
                    INNER JOIN {$table_prefix}posts ON {$table_prefix}posts.ID = {$table_prefix}postmeta.post_id
                    WHERE {$table_prefix}postmeta.meta_key = '_bbp_old_reply_id'
                    AND {$table_prefix}postmeta.meta_value = '" . $_GET['p'] . "';";
      }else if (!empty($_GET['t'])) {
          $query = "SELECT {$table_prefix}posts.guid FROM {$table_prefix}postmeta
                    INNER JOIN {$table_prefix}posts ON {$table_prefix}posts.ID = {$table_prefix}postmeta.post_id
                    WHERE {$table_prefix}postmeta.meta_key = '_bbp_old_topic_id'
                    AND {$table_prefix}postmeta.meta_value = '" . $_GET['t'] . "';";
      }
    
      // Set the new url to the default url
      $url = $defaulturl;
    
      // Check if we need to make a database connection.
      if (!empty($query)) {
        //echo "connecting...<br>";
        // Make a connection
        $mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die("mysqli connect error: "+mysqli_connect_error());
    
        // Check the connection.
        if (!mysqli_connect_errno()) {
          // Run the query.
          //echo $query."<br>";
          $result = mysqli_query($mysqli,$query) or die("mysqli query error: ".mysql_error($mysqli));
    
          // Get the new URL.
          if ($result) {
            $row = $result->fetch_array(MYSQLI_ASSOC);
            $guid = trim($row["guid"]);
            if (!empty($guid)) {
              $url = $guid;
            }
          }
    
          // Free the result set.
          $result->free();
    
          // Close the connection.
          mysqli_close($mysqli);
        }
      }
    
      //var_dump($url);
    
      // Write the header.
      header("Location: " . $url, true, 301);
    ?>
    

    Schoelje
    Participant

    @schoelje

    Glad you found it useful and thanks for posting back your code.

    Thanks guys for sharing!


    senatorman
    Participant

    @senatorman

    Looks great, but is this usefull when my old phpbb forum is moved to a sub-domain, and my new forum is now on the main-domain?

    For example.
    My old phpbb is moved to archive.domain.com
    My Bbpres is on domain.com

    How can u use your code, and where must i place it?

    The wrong old Google phpbb urls goes to domain.com


    senatorman
    Participant

    @senatorman

    .


    senatorman
    Participant

    @senatorman

    I’ve edit the viewtopic in my old pbpbb forum in my sub-domain

    And do the personal DB settings, and nog i get this error

    Fatal error: Call to a member function free() on a non-object in /home/***/***/public_html/archief/viewtopic.php on line 48

    Is there a way to export al old and new urls to a csv file. So i can import this in my redirect plugin on my new forum?
    Google send many visitors with the old url that not can find on my new bbpress forum. So i can catch these visitors and redirect them


    Schoelje
    Participant

    @schoelje

    Hi senatorman,

    My apologies for the late reply. I haven’t looked at this for quite some time and I haven’t tested it on any other situation/environment than my own.

    If you still need it: I usually use phpMyAdmin to export data to a csv file.


    senatorman
    Participant

    @senatorman

    Thank you for your reply.

    I’ve had already solved the problem. an it works now for me.


    senatorman
    Participant

    @senatorman

    above is a Spampost


    en10
    Participant

    @en10

    Hello,

    Is it available for phpBB 3.1.x?

    I tried the script of @hypnoticdan but I don’t have

    http://my_phpbb_domain.com/viewtopic.php?f=1&t=2
    to:
    http://my_wordpress_domain.com/forums/topic/corresponding_topic/

    I get only a redirection from phpbb to bbpress (index to index)

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
Skip to toolbar