Home > Backend Development > PHP Tutorial > php用header函数实现301跳转代码实例_php实例

php用header函数实现301跳转代码实例_php实例

WBOY
Release: 2016-06-07 17:22:55
Original
808 people have browsed it

PHP 301跳转的小代码

复制代码 代码如下:

 $the_host = $_SERVER['HTTP_HOST'];
 $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
 if($the_host !== 'www.php.net')
 {
     //echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: http://www.php.net' . $_SERVER['PHP_SELF']  . $request_uri);
 }
?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template