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

XF 1.4 Canonical building of threads by id returns wrong URL?

Discussion in 'Installation, Upgrade, and Import Support' started by mqudsi, Feb 19, 2015.

  1. mqudsi

    mqudsi Member

    I just bit the bullet and switched to XF from vB, but I'm having a bit of a problem that I don't think is actually caused by the import?

    In the vB import scripts, this snippet:

    $target = XenForo_Link::buildPublicLink('canonical:threads', array('thread_id' => $newId));
    Is returning the wrong result. $newId arrives correctly, but buildPublicLink returns a link to the thread containing the post that has id = $newId instead of the thread with that id.

    For example, for the request with $newId = 642, XF takes me to

    Instead of

    I know absolutely zero about XF, but my guess is that 'thread_id' needs to be something else?
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  3. mqudsi

    mqudsi Member

    No, I actually even modified the script to hard code the thread id and printed the value of the url immediately after the call for thread.
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Hmm. That shouldn't be happening.

    Possibilities include:

    1) An addon interfering with the threads route (try disabling addons).

    2) PHP opcode caches like Zend Optimizer can cause all sorts of weird behavior at the code level if the cache is having problems. Try disabling any such extensions in PHP.

    3) Bad file upload. Try re-uploading the original XF files.
  5. mqudsi

    mqudsi Member

    It worked by looking up the thread and redirecting to it. Code now looks like this:

    $startTime = microtime(true);
    $fileDir = dirname(__FILE__);
    if (file_exists($fileDir . '/301config.php'))
        include($fileDir . '/301config.php');
    require($fileDir . '/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
    XenForo_Application::initialize($fileDir . '/library', $fileDir);
    XenForo_Application::set('page_start_time', $startTime);
    $http = new Zend_Controller_Request_Http();
    $inputHandler = new XenForo_Input($http);
    $input = $inputHandler->filter(array(
        't' => XenForo_Input::UINT,
        'p' => XenForo_Input::UINT
    if(preg_match('/(?:showthread|printthread)\.php(?:\/|\?)([0-9]+)(?:-[^\/]+)/', $http->getRequestUri(), $matches) && count($matches) >= 1){   
        $input['t'] = intval($matches[1]);
    $target = false;
    if ($input['t'])
        $thread = XenForo_Model::create('XenForo_Model_Thread')->getThreadById($input['t']);
        $target = XenForo_Link::buildPublicLink('canonical:threads', $thread);
    else if ($input['p'])
        $target = XenForo_Link::buildPublicLink('canonical:posts', array('post_id' => $input['p']));
    if (!$target)
        $target = XenForo_Link::buildPublicLink('canonical:index');
    $response = new Zend_Controller_Response_Http();
    $response->setRedirect(XenForo_Link::convertUriToAbsoluteUri($target), 301);
    sdrothrock and Robust like this.
  6. sdrothrock

    sdrothrock Member

    This is from two years, but I was having a similar problem and this fixed it. Thank you!

Share This Page