js、asp、php实现301跳转效果

来源:岁月联盟 编辑:exp 时间:2012-08-05

301重定向是当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息 (header)中的状态码的一种,表示本网页永久性转移到另一个地址。其它常见的状态码还包括,200表示一切正常,404网页找不到,302暂时转向,等等。

javascript的301重定向代码:


1 <script language=javascript> 

2 if (document.domain =='yourolddomain')  

3     this.location = "http://yourdomain" + this.location.pathname + this.location.search; 

4 </script>

 

ASP下的301重定向代码:


1 <%@ Language=VBScript %> 

2   

3 <% 

4   

5 Response.Status="301 Moved Permanently" 

6   

7 Response.AddHeader "Location","http://www.2cto.com " 

8   

9 %>

PHP下的301重定向代码:


1 <?php 

2 $url="http://www.2cto.com ".$_SERVER["REQUEST_URI"]; 

3 header("HTTP/1.1 301 Moved Permanently"); 

4 header ("Location:$url"); 

5 ?>

推荐使用JavaScript+html跳转,效率最高。