301跳转代码,还有使用方法
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^111cn.net [nc]
rewriterule ^(.*)$ https://domain.com /$1 [r=301,nc]
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.domain1.com [nc]
rewriterule ^(.*)$ http://www.domain2.com/$1 [r=301,nc]
只需在PHP网页顶部输入下面的代码
<?php
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: https://domain.com ");
?>
1、建立301.php文件
?php
$the_host = $_SERVER['HTTP_HOST'];//取得当前域名
$the_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//判断地址后面部分
$the_url = strtolower($the_url);//将英文字母转成小写
if($the_url=="/index.php")//判断是不是首页
{
$the_url="";//如果是首页,赋值为空
}
if($the_host !== 'https://domain.com')//如果域名不是带www的网址那么进行下面的301跳转
{
header('HTTP/1.1 301 Moved Permanently');//发出301头部
header('Location:https://domain.com '.$the_url);//跳转到带www的网址
}
?>
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
<meta charset="gb2312">
<title>正在跳转中</title>
<meta http-equiv="refresh" content="0;url=https://domain.com" />
<meta http-equiv="Cache-Control" content="no-transform" />
</head>
<body>
</body>
</html>
这里 content=”0; 的0代表时间,可以自己设置。
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
<meta charset="gb2312">
<title>正在跳转中</title>
</head>
<body>
<form name=loading>
<p align=center> <font color="#0066ff" size="2">正在进入,请稍等</font><font color="#0066ff" size="2" face="Arial">...</font>
<input type=text name=chart size=46 style="font-family:Arial; font-weight:bolder; color:#0066ff; background-color:#fef4d9; padding:0px; border-style:none;">
<input type=text name=percent size=47 style="color:#0066ff; text-align:center; border-width:medium; border-style:none;">
<script>
var bar=0
var line="||"
var amount="||"
count()
function count(){
bar=bar+2
amount =amount + line
document.loading.chart.value=amount
document.loading.percent.value=bar+"%"
if (bar<99)
{setTimeout("count()",100);}
else
{window.location = "https://domain.com";}
}</script>
</p>
</form>
<p align="center"> 如果您的浏览器不支持跳转,<a style="text-decoration: none" href="https://domain.com"><font color="#FF0000">请点这里</font></a>.</p>
</body>
</html>
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
<title>正在进入</title>
</head>
<body>
<script language='javascript'>document.location = https://domain.com''</script>
</body>
</html>
2、在网页文件中调用301.php
<?php include("301.php");?>
将这个代码放到你所有网页的最前面。