PHP实现301跳转

PHP实现301跳转的方法:

$theHost = $_SERVER['HTTP_HOST'];
$theUrl = isset($_SERVER['REQUEST_URI'])? $_SERVER['REQUEST_URI']:'';
$theUrl = strtolower($theUrl);
if($theUrl == '/index.php')
{
  $theUrl = '';
}
if($theHost != 'www.test.com')
{
  header('HTTP/1.1 301 Moved Permanently');
  header('Location:http://www.test.com'.$the_url);
}

将此代码放在*.php首行,或者放置在config.php中。

posted @ 2016-04-02 09:01  izhenyang  阅读(734)  评论(0)    收藏  举报