PHP做301重定向设置的代码方法
作者:互联网
<?php
$the_host = $_SERVER['HTTP_HOST'];//取得当前域名
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//判断地址后面是否有参数
if($the_host == 'baidu.com')//把这里的域名换上你想要的
{
header('HTTP/1.1 301 Moved Permanently');//发出301头部
header('Location: http://www.baidu.com'.$request_uri);//跳转到你希望的地址格式
}
//实例应用
$the_host = $_SERVER['HTTP_HOST'];
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
if($the_host == 'www.ximengmanong.com'||$the_host == 'www.moumoumou.com')
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://www.ximengmanong.com'.$request_uri);
}
?>
标签:www,HTTP,重定向,301,request,header,PHP,com 来源: https://blog.csdn.net/weixin_44276556/article/details/122212543