1. Приветствуем Вас на неофициальном форуме технической поддержки XenForo на русском языке. XenForo - коммерческий форумный движок от бывших создателей vBulletin, написанный на PHP.

Делаем для XenForo редирект ссылок с vB4 (без vBSEO)

Тема в разделе "Переезд на XenForo c других движков", создана пользователем bumz, 26.12.2010.

Загрузка
  1. bumz

    bumz Club line

    Регистрация:
    11.11.10
    Сообщения:
    99
    Симпатии:
    75
    При переносе форума с vb на XenForo вид ссылок на разделы /темы меняется:
    у vb 4 - showthread.php?xxx-название темы
    у XF - threads/название темы.xxx (где xxx - id темы)
    В связи с этим необходим редирект для старых ссылок. Например, у меня на форуме около 70% - трафик с поисковых систем, и если все старые ссылки будут "мёртвыми" - сами понимаете, будет не хорошо!

    Чтобы этого не произошло, делаем следущее:
    -в корне создайте файл forumdisplay.php со следующим содержанием:
    Код:
    <?php
    
    $startTime = microtime(true);
    $fileDir = dirname(__FILE__);
    
    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);
    
    $inputHandler = new XenForo_Input(new Zend_Controller_Request_Http());
    
    $input = $inputHandler->filter(array(
        'f' => XenForo_Input::UINT,
    ));
     
    $http = new Zend_Controller_Request_Http();
    if(preg_match('/forumdisplay\.php(?:\/|\?)([0-9]+)(?:-[^\/]+)/', $http->getRequestUri(), $matches) && count($matches) >= 1){
        $input['f'] = intval($matches[1]);
    }
    
    $importModel = XenForo_Model::create('XenForo_Model_Import');
    
    $target = false;
    if ($input['f'])
    {
        $newId = $importModel->mapNodeId($input['f']);
        if ($newId)
        {
            $target = XenForo_Link::buildPublicLink('forums', array('node_id' => $newId));
        }
    }
    
    if (!$target)
    {
        $target = XenForo_Link::buildPublicLink('index');
    }
    
    $response = new Zend_Controller_Response_Http();
    $response->setRedirect(XenForo_Link::convertUriToAbsoluteUri($target), 301);
    $response->sendResponse();
    и фаил showthread.php
    Код:
    <?php
    
    $startTime = microtime(true);
    $fileDir = dirname(__FILE__);
    
    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);
    
    $inputHandler = new XenForo_Input(new Zend_Controller_Request_Http());
    
    $input = $inputHandler->filter(array(
        't' => XenForo_Input::UINT,
        'p' => XenForo_Input::UINT
    ));
    
    $http = new Zend_Controller_Request_Http();
    if(preg_match('/showthread\.php(?:\/|\?)([0-9]+)(?:-[^\/]+)/', $http->getRequestUri(), $matches) && count($matches) >= 1){
        $input['t'] = intval($matches[1]);
    }
    
    $importModel = XenForo_Model::create('XenForo_Model_Import');
    
    $target = false;
    if ($input['p'])
    {
        $newId = $importModel->mapPostId($input['p']);
        if ($newId)
        {
            $target = XenForo_Link::buildPublicLink('posts', array('post_id' => $newId));
        }
    }
     else if ($input['t'])
    {
        $newId = $importModel->mapThreadId($input['t']);
        if ($newId)
        {
            $target = XenForo_Link::buildPublicLink('threads', array('thread_id' => $newId));
        }
    }
    
    if (!$target)
    {
        $target = XenForo_Link::buildPublicLink('index');
    }
    
    $response = new Zend_Controller_Response_Http();
    $response->setRedirect(XenForo_Link::convertUriToAbsoluteUri($target), 301);
    $response->sendResponse();
    -добавляем в .htaccess следущее:
    Код:
    RewriteRule [^/]+/([\d]+)-.+-([\d]+).html showthread.php?t=$1&page=$2 [NC,L]
    RewriteRule [^/]+/([\d]+)-.+.html showthread.php?t=$1 [NC,L]
    .

    Т.е. .htaccess должен получиться следующего содержания:
    Код:
    #    Mod_security can interfere with uploading of content such as attachments. If you
    #    cannot attach files, remove the "#" from the lines below.
    #<IfModule mod_security.c>
    #    SecFilterEngine Off
    #    SecFilterScanPOST Off
    #</IfModule>
    
    <IfModule mod_rewrite.c>
        RewriteEngine On
    
    RewriteRule [^/]+/([\d]+)-.+-([\d]+).html showthread.php?t=$1&page=$2 [NC,L]
    RewriteRule [^/]+/([\d]+)-.+.html showthread.php?t=$1 [NC,L]
    
    
        #    If you are having problems with the rewrite rules, remove the "#" from the
        #    line that begins "RewriteBase" below. You will also have to change the path
        #    of the rewrite to reflect the path to your XenForo installation.
        #RewriteBase /xenforo
    
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^(data|js|styles|install) - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    </IfModule>
    Важно! В данном случае это работает, если Вы использовали на vb4 ЧПУ, без vbSEO!

    p.s. Если данный метод уже описан на форуме, то прошу прощения..... пользовался поиском, не нашёл!

    p.p.s. У меня работает! ))
     
    Gatses, rvint, Xokage и 2 другим нравится это.
  2. Gatses

    Gatses Местный

    Регистрация:
    05.02.11
    Сообщения:
    421
    Симпатии:
    584
    Версия XF:
    1.5.9
    Кто-нибудь заморачивался по поводу перенаправления по старым ссылкам на пользователей? :)
     

Поделиться этой страницей