Перенаправления HTTP 302 в MediaWiki
В MediaWiki по умолчанию используются перенаправления, которые дублируют страницы (что теоретически может негативно отразиться на кешировании и рейтингах в поисковиках). Обычно в такой же ситуации используются перенаправления с кодом 302, которые без каких-либо других действий перенаправляют браузеры клиентов и поисковики на новый адрес. Чтобы сделать в MedaWiki так же, можно использовать расширение http://www.mediawiki.org/wiki/Extension:HTTP302Found
Установка - поместить файл HTTP302Found.php в папку extensions/HTTP302Found и прописать его в LocalSettings.php так (проверено для версии MediaWiki 1.16.0):
require_once("$IP/extensions/HTTP302Found/HTTP302Found.php");
В несколько доработанном напильником виде (убран непонятно зачем нужный GET-параметр) расширение выглядит так:
<?php
/* MediaWiki extension to force an external HTTP 302 redirect instead of internal redirects
* Copyright (C) 2009 Ian Weller <ian@ianweller.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
$wgExtensionCredits["other"][] = array(
'path' => __FILE__,
'name' => "HTTP 302 Found",
'description' => "Forces an external HTTP 302 redirect instead of internal redirects",
'version' => "1.0",
'author' => "Ian Weller",
'url' => "http://www.mediawiki.org/wiki/Extension:HTTP302Found",
);
$wgHooks['InitializeArticleMaybeRedirect'][] = 'http302_redirect_hook';
$wgHooks['ArticlePageDataBefore'][] = 'http302_redirect_notification_hook';
// This function causes the actual redirect
function http302_redirect_hook($title, $request, &$ignoreRedirect, &$target, &$article)
{
if (!$ignoreRedirect && $article->isRedirect()) {
if (($target = $article->followRedirect()) instanceof Title) {
//$target = $target->getFullURL()."?rd=".$title->mUrlform;
$target = $target->getFullURL();
}
}
return true;
}
// This function handles the "rd" GET variable and forces the "Redirected from ..." message
function http302_redirect_notification_hook(&$article, &$fields)
{
// $title = Title::newFromText($_GET["rd"]);
// $article->setRedirectedFrom($title);
return true;
}
Двойные перенаправления не перенаправляются сами, их надо исправлять через страницу Служебная:DoubleRedirects или ботом.
Перенаправления HTTP 302 в MediaWiki относится к темам: |