http://www.wocaoseo.com/thread-193-1-1.html
301对于seo来说有举足轻重的作用,大家可以参考《良好的收录始于301》;做301的方式有很多种,每一种方式都有他的独立性和约束性。然后代码301却能通用。
代码301的原理很简单,假设现在有两个网页A和B我们要把A网页定向到B网页,当用户访问A网页的时候,服务器会解析一段301代码并返回B网页以及http状态。
下面以asp程序为例子具体说明代码301的用法。
第一步、建立index.asp页面放入下面代码(如果原来就存在可以移动到其他文件夹)
ASP301代码:
- <% if left(request.ServerVariables(“HTTP_HOST”),4)<>”www.” then
- url = “http://www.”&request.ServerVariables(“HTTP_HOST”)
- if Request.ServerVariables(“QUERY_STRING”) <> “” then
- url = url & Request.ServerVariables(“SCRIPT_NAME”) & online casino game “?” & Request.ServerVariables(“QUERY_STRING”)
- end if
- Response.Status = “301 Moved Permanently”
- Response.AddHeader “Location”, url
- end if %>
- <!–#include file=”index.htm”–>
复制代码
第二步、网站默认启动首页为index.asp;
第三步、调用原来的首页;
下面给出php301代码:- <?php if(substr($_SERVER["HTTP_HOST"],0,4)!=”www.”)
- {
- $url= “http://www.”.$_SERVER["HTTP_HOST"];
- if ($_SERVER["QUERY_STRING"]!=”") {
- $url = $url.$_SERVER["SCRIPT_NAME"] .”?”.$_SERVER["QUERY_STRING"];
- }
- header(“HTTP/1.1 301 Moved Permanently”);
- header(“location:$url”); } ?>
- <!–#include file=”index.html”–>
复制代码 代码301完美解决虚拟空间永久重定向 |