天天看点

asp301重定向将不带www重定向到带www上

网站在域名更改的时候都会面对的一个问题就是网站的重定向,正确的域名重定向可以保留网站的在搜索引擎中的权重,从SEO角度出发建议使用301重定向,在实现301重定向的时候除在服务器上设置之外,也可以通过代码做301跳转。以下是asp301重定向的代码,除了主域名需要注意301重定向之外,在启用二级域名的网站也是需要进行301重定向处理代码如下:

  <%

  website=request.ServerVariables("Server_name")

  if website="cnshuziyouhua.com" then

  Response.Status="301 Moved Permanently"

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

  end if

  website=request.ServerVariables("Server_name")

  if website="youhua.cnshuziyouhua.com" then

  Response.Status="301 Moved Permanently"

  Response.AddHeader "Location","http://cnshuziyouhua.com/youhua/"

  end if

  %>

将asp301重定向将不带www重定向到带www上 第二种方法:

<%

Dim dm

dm=Request.ServerVariables("Server_name")

if left(dm,3)<>"www" then

Response.Status="301 Moved Permanently"

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

Response.End

end if

%>

<%

Dim dm

dm=Request.ServerVariables("Server_name")

if left(dm,3)<>"www" then

Response.Status="301 Moved Permanently"

Response.AddHeader

<%

if request.ServerVariables("SERVER_NAME")="xingyejixie.com" then

Response.Status="301 Moved Permanently"

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

Response.End

end if

%>

<%

if request.ServerVariables("SERVER_NAME")="yinduntewei.com" or request.ServerVariables("SERVER_NAME")="sjzydtw.com" or request.ServerVariables("SERVER_NAME")="www.sjzydtw.com" then

Response.Status="301 Moved Permanently"

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

Response.End

end if

%>

对于是否网站301重定向正确可以通过一下网站进行301重定向检测。 http://www.seoconsultants.com/tools/check-server-headers-tool/