温馨提示×

phpcms如何做301跳转

小新
216
2020-12-29 09:09:07
栏目: 编程语言

phpcms如何做301跳转

phpcms做301跳转的方法:

方法一:

在根目录下找到.htaccess文件,并添加以下代码,保存上传即设置成功。

RewriteEngine on

RewriteCond %{HTTP_HOST} !^baidu.com$ [NC]

RewriteRule ^(.*)$ http://baidu.com/$1 [L,R=301]

方法二:

1.在网站根目录下的index.php文件中设置,代码如下:

$the_host = $_SERVER[’HTTP_HOST’];//取得当前域名

if(strtolower($the_host) != ’www.baidu.com’)//把这里的域名换上你想要的

{ $URIRedirect=$_SERVER[’REQUEST_URI’]; //获取域名后的参数

if(strtolower($URIRedirect)=="/index.php")//判断是参数为/index.php就显示为/

{

$URIRedirect="/";

}

header("HTTP/1.1 301 Moved Permanently");//发出301头部

header("Location: http://www.baidu.com".$URIRedirect);//跳转到你希望的地址格式

exit();

}

2.在对应网页文件中调用index.php即可,代码如下:

<?php  include("index.php");  //301重定向 ?>

0