2012-02-22 175 views
0

我使用這個Joomla 1.5插件做重定向。工程很好,但它會返回一個「303看到其他」重定向狀態,而不是搜索引擎優化301如何更改303重定向到301在PHP中重定向

有什麼可以做的下面的代碼爲插件,使其301重定向?

<?php 
/** 
* JRedirect plugin 
* 
* @author Ross Farinella 
* @version 1.0.0 
* @license GPL 
*/ 

defined('_JEXEC') or die('Restricted access'); 

global $mainframe; 
$mainframe->registerEvent('onAfterRoute', 'plgSystemCheckJRedirect'); 

/** 
* Checks to see if the current URL being requested is one of the "special" URLs 
* and redirects the application as necessary 
*/ 
function plgSystemCheckJRedirect() 
{ 
global $mainframe; 

// get the plugin parameters 
$tmp = JPluginHelper::getPlugin("system","jredirect"); 
$params = new JParameter($tmp->params); 

// get the current URI 
$current = JRequest::getURI(); // "/something.html" 

$urls = $params->get('urls'); 
$urls = explode("\n",$urls); 
foreach($urls as $url) 
{ 
    // get the user-entered urls 
    list($toCheck,$toRedirect) = explode("|",$url); 

    // check if we're at this url 
    if($current == "/".$toCheck) { 
     // do the redirect 
     $mainframe->redirect($toRedirect); 
    } 
} 
} 


?> 
+1

我們需要選擇t的內部他的功能是'$ mainframe-> redirect()',但它應該像添加一個頭部(「HTTP/1.1 301永久移動」)一樣簡單;'在頭部之前調用(「Location:」)'。 – 2012-02-22 18:25:20

+0

在這裏右邊的「相關」問題中的許多其他例子都有關於如何完成的例子,當你找到放置它的正確位置時。 – 2012-02-22 18:25:58

+0

謝謝邁克爾,我只是想找到在哪裏添加,即時通訊使用第三方插件,所以我會假設我不能把這段代碼放在上面的文件 – Simsan 2012-02-22 18:33:47

回答

3

按照Joomla documentation(或者更確切地說,the source),你應該能夠通過改變

$mainframe->redirect($toRedirect); 

這樣做

$mainframe->redirect($toRedirect,'','message',true); 

所以:

<?php 
/** 
* JRedirect plugin 
* 
* @author Ross Farinella 
* @version 1.0.0 
* @license GPL 
*/ 

defined('_JEXEC') or die('Restricted access'); 

global $mainframe; 
$mainframe->registerEvent('onAfterRoute', 'plgSystemCheckJRedirect'); 

/** 
* Checks to see if the current URL being requested is one of the "special" URLs 
* and redirects the application as necessary 
*/ 
function plgSystemCheckJRedirect() 
{ 
global $mainframe; 

// get the plugin parameters 
$tmp = JPluginHelper::getPlugin("system","jredirect"); 
$params = new JParameter($tmp->params); 

// get the current URI 
$current = JRequest::getURI(); // "/something.html" 

$urls = $params->get('urls'); 
$urls = explode("\n",$urls); 
foreach($urls as $url) 
{ 
    // get the user-entered urls 
    list($toCheck,$toRedirect) = explode("|",$url); 

    // check if we're at this url 
    if($current == "/".$toCheck) { 
     // do the redirect 
     $mainframe->redirect($toRedirect,'','message',true); 
    } 
} 
} 


?> 
+0

這完美的工作。謝謝! – Simsan 2012-02-22 18:40:59