PHP 301跳转的小代码

来源:互联网 发布:形状优化设计 编辑:程序博客网 时间:2024/06/12 20:05

分享一例php 301跳转的代码,很简单,主要是用header函数实现转。

代码:

<?php   
 $the_host = $_SERVER['HTTP_HOST'];
 $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
 if($the_host !== 'www.jbxue.com')
 {
     //echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: http://www.jbxue.com' . $_SERVER['PHP_SELF']  . $request_uri);
 }
?>