Jump to content


Photo

Latest IPB update broke old link redirection


  • Please log in to reply
9 replies to this topic

#1 jason hilton

jason hilton

    IPB Newbie

  • +Clients
  • 14 posts

Posted 01 February 2012 - 02:09 PM

Hello all,

A long time ago (over a year) I converted from phpBB to IPB. Everything went fine with the conversion and everything was working perfectly up until the last IPB update.

Now, all the old redirects (/forum/viewtopic.php?t=1234) go to a IPB 404 page.
I've looked at the redirect files and the databse and everything is still there and running the query manually returns the correct result.
$row = $DB->buildAndFetch( array( 'select' => 'ipb_id', 'from' => 'conv_link', 'where' => "foreign_id='".ipsRegistry::$request['t']."' AND type='topics' AND app='".$app['app_id']."'" ) );

Any ideas?
  • vashkvartal likes this

#2 jason hilton

jason hilton

    IPB Newbie

  • +Clients
  • 14 posts

Posted 01 February 2012 - 02:17 PM

Taking a look at the source code of the 404 page, it appears that the redirect files are not redirecting to the correct url, as the base URL of all links becomes:
http://site.com/viewtopic.php?/user/1-jasonh/


#3 jason hilton

jason hilton

    IPB Newbie

  • +Clients
  • 14 posts

Posted 01 February 2012 - 02:39 PM

For example, running a SQL query manually, substituting for variables
SELECT `ipb_id`
FROM conv_link
WHERE `foreign_id` =18327
AND `type` = 'topics'
AND app =1
returns:
ipb_id=16010
and then manually substituting the id as /index.php?showtopic=16010
returns the correct topic without a 404.
So something with the update has changed the way the php redirect files deals with redirecting to the proper URL.

#4 jason hilton

jason hilton

    IPB Newbie

  • +Clients
  • 14 posts

Posted 01 February 2012 - 03:05 PM

Ok, so I've been trying to debug this and found something interesting.

I stripped viewtopic.php down to just:
require_once 'config.php';
require_once( IPB_PATH.'/initdata.php' );
require_once( IPB_PATH.'/'.CP_DIRECTORY.'/sources/base/ipsRegistry.php' );
require_once( IPB_PATH.'/'.CP_DIRECTORY.'/sources/base/ipsController.php' );

$registry = ipsRegistry::instance();
$registry->init();
$DB	   = $registry->DB();

$row = $DB->buildAndFetch( array( 'select' => 'ipb_id', 'from' => 'conv_link', 'where' => "foreign_id='".ipsRegistry::$request['t']."' AND type='topics' AND app='".$app['app_id']."'" ) );
echo $row['ipb_id'];
Somehow, with no redirect, only an echo, it's STILL going to the IPB 404 page.
I don't even get how that's even possible unless the require files are somehow overriding the file entirely.

#5 jason hilton

jason hilton

    IPB Newbie

  • +Clients
  • 14 posts

Posted 01 February 2012 - 05:42 PM

Since I couldn't figure out what the hell was happening with it, I just wrote a new one... I know it doesn't do any checking (does that even matter?), but I'm going to use it until someone figures out why the IPB one isn't working.

<?php
$oldtopic = $_GET["t"];
$con = mysql_connect("dbhost","dbuser","dbpass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("dbname", $con);
$result = mysql_query("SELECT `ipb_id` FROM conv_link WHERE `foreign_id` = '$oldtopic' AND `type` = 'topics' LIMIT 1" );
$row = mysql_fetch_array($result);
mysql_close($con);
Header( "HTTP/1.1 301 Moved Permanently" );
Header("Location: http://site.com/index.php?showtopic=".$row['ipb_id']);
?>

  • vitoreis likes this

#6 -GR-

-GR-

    Advanced Member

  • +Clients
  • 205 posts

Posted 02 February 2012 - 11:25 AM

Ok, so I've been trying to debug this and found something interesting.

I stripped viewtopic.php down to just:

require_once 'config.php';
require_once( IPB_PATH.'/initdata.php' );
require_once( IPB_PATH.'/'.CP_DIRECTORY.'/sources/base/ipsRegistry.php' );
require_once( IPB_PATH.'/'.CP_DIRECTORY.'/sources/base/ipsController.php' );

$registry = ipsRegistry::instance();
$registry->init();
$DB	   = $registry->DB();

$row = $DB->buildAndFetch( array( 'select' => 'ipb_id', 'from' => 'conv_link', 'where' => "foreign_id='".ipsRegistry::$request['t']."' AND type='topics' AND app='".$app['app_id']."'" ) );
echo $row['ipb_id'];
Somehow, with no redirect, only an echo, it's STILL going to the IPB 404 page.
I don't even get how that's even possible unless the require files are somehow overriding the file entirely.


I know on the redirect files I have been messing with you have to strip the "t=" and get just the number for the topic or forum id, otherwise you are searching for t=1234 and won't find a match.

#7 jason hilton

jason hilton

    IPB Newbie

  • +Clients
  • 14 posts

Posted 02 February 2012 - 01:50 PM

I know on the redirect files I have been messing with you have to strip the "t=" and get just the number for the topic or forum id, otherwise you are searching for t=1234 and won't find a match.

Yeah I'm not sure what was going on with the IPB redirect file, I did a lot of debugging and couldn't get it to work. I think something has changed in ipsRegistry.php that prevents them from working the way they did before.

Anyway, the code I posted (post 5) doesn't require any ipb files. It manually does a mysql select from a PHP $_GET "t" and then sets the result as the header location. It works perfectly, I don't know why IPB made such a complicated redirect in the first place.

#8 -GR-

-GR-

    Advanced Member

  • +Clients
  • 205 posts

Posted 02 February 2012 - 02:01 PM

Yeah I'm not sure what was going on with the IPB redirect file, I did a lot of debugging and couldn't get it to work. I think something has changed in ipsRegistry.php that prevents them from working the way they did before.

Anyway, the code I posted (post 5) doesn't require any ipb files. It manually does a mysql select from a PHP $_GET "t" and then sets the result as the header location. It works perfectly, I don't know why IPB made such a complicated redirect in the first place.


I know what you mean, it is nice though keeping with using the same classes and methods though. We are getting ready to do the live conversion on our vb4 site next weekend and I have been busy trying to get everything in place and the redirects were one of the things I just took care of which is why it was fresh in my brain about having to strip the t= out.

I guess using their classes and methods if you change your database info for some reason it would be one less thing to worry about but it isn't like that happens too often if ever.

#9 claretalabs

claretalabs

    IPB Newbie

  • Visitors
  • Pip
  • 1 posts

Posted 13 March 2012 - 07:08 AM

please be careful about classes and methods...............................................its important now...................

#10 sobrenome

sobrenome

    Spam Happy

  • +Clients
  • 563 posts

Posted 05 June 2012 - 08:03 PM

Thanks man, your home made script saved my life!!!

Take a look at my agonies here: http://community.inv...in-mod-rewrite/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users