如何在PHP中将303重定向更改为301重定向


how to change 303 redirect to a 301 Redirect in PHP

我使用这个Joomla 1.5插件进行重定向。效果很好,但它返回"303查看其他"重定向状态,而不是SEO友好的301

对于插件的以下代码,有什么可以做的吗,使其成为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);
    }
}
}

?>

根据Joomla文档(或者更确切地说,源代码),您应该能够通过更改来做到这一点

$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);
    }
}
}

?>