301重定向代码版

什么是301重定向呢?说白了就是通过各种的方法将各种网络请求重新定个方向转到其它位置。当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码的一种,表示本网页永久性转移到另一个地址.


1
php 301重定向代码

<?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 !== 'www.123049.net')//如果域名不是带www的网址那么进行下面的301跳转

{

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

header('Location:http://www.zhizhuowz.com/'.$the_url);//跳转到带www的网址

}

?>

2
html 301重定向代码,可以在页头加入如下代码:

<meta http-equiv="refresh" content="0; url=http://www.zhizhuowz.com/">

3
ASP 301重定向代码,

<%

Response.Status="301 Moved Permanently"

Response.AddHeader "Location","http://www.zhizhuowz.com/"

Response.End

%>

4
Apache下301转向代码 ,新建.htaccess文件,输入下列内容(需要开启mod_rewrite):

RewriteCond %{HTTP_HOST} ^youduan.net [NC]

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

5
http.ini伪静态规则的主机是最让人头疼的,因为有三个版本的伪静态规则:ISAPI_Rewrite 1.X,ISAPI_Rewrite2.X,ISAPI_Rewrite 3.x总共三个版本.选择适合自己的。代码如下。

ISAPI_Rewrite 1.X的代码如下:

[ISAPI_Rewrite]

CacheClockRate 3600

RepeatLimit 32

RewriteCond Host: ^youduan.net$

RewriteRule (.*) http://www.zhizhuowz.com/ [R,I]

ISAPI_Rewrite 2.X的代码如下:

[ISAPI_Rewrite]

CacheClockRate 3600

RepeatLimit 32

RewriteCond Host: ^youduan.net$

RewriteRule (.*) http://www.zhizhuowz.com/$1 [I,RP]

ISAPI_Rewrite 3.X的代码如下:

[ISAPI_Rewrite]

CacheClockRate 3600

RepeatLimit 32

RewriteCond %{HTTP:Host} ^youduan.net$

RewriteRule (.*) http://www.zhizhuowz.com/$1 [NC,R=301]

猜你喜欢

转载自www.cnblogs.com/hongyuyingxiao/p/10177687.html