301重定向是当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息 (header)中的状态码的一种,表示本网页永久性转移到另一个地址。其它常见的状态码还包括,200表示一切正常,404网页找不到,302暂时转向,等等。
javascript的301重定向代码:
<script language=javascript> if (document.domain =='yourolddomain') this.location = "http://yourdomain" + this.location.pathname + this.location.search; </script>
ASP下的301重定向代码:
<%@ Language=VBScript %> <% Response.Status="301 Moved Permanently" Response.AddHeader "Location"," " %>
PHP下的301重定向代码:
<?php $url=" ".$_SERVER["REQUEST_URI"]; header("HTTP/1.1 301 Moved Permanently"); header ("Location:$url"); ?>