漫步浪尖

记载Xhtml,Css,Javascript,W3c,Seo,计算机,服务器等Web技术相关的心得.

Zblog中Microsoft VBScript 运行时错误的处理Firefox中列表li内容偏左的解决方式

用免费asp空间做301重定向

多功能的Asp单页实现多网站多域名的301重定向,但有朋友说,只想给一个www域名给另外一个不带www的301重定向怎么转,本文解决效果:访问www.qqcampus.org,301到qqcampus.org,从而避免搜索引擎的重复收录,达到搜索引擎友好的效果
把以下代码保存为index.asp,上传到支持Asp顶级域名绑定免费Asp空间,然后在免费Asp空间后台设置index.asp为默认首页,并绑定www.qqcampus.org(举例)
<%
 dim s_domain
 s_domain=lcase(Request.ServerVariables("SERVER_NAME"))
 if instr(1,s_domain,"www.qqcampus",1)>0 then
  Response.Status="301 Moved Permanently"
  Response.AddHeader "Location", "http://qqcampus.org"
  Response.End
 end if
%>

需要注意一点的是,如果是要把qqcampus.org转到带www的www.qqcampus.org上,这样做是不对的,因为asp301重定向代码instr(1,s_domain,"qqcampus",1)>0的意思是域名里包含qqcampus,而qqcampus.org和www.qqcampus.org都包含这个,则会造成死循环,应该做一些改动:

<%
 dim s_domain
 s_domain=lcase(Request.ServerVariables("SERVER_NAME"))
 if s_domain="qqcampus.org" then
  Response.Status="301 Moved Permanently"
  Response.AddHeader "Location", "http://www.qqcampus.org"
  Response.End
 end if
%>

或者这样也行

<%
 dim s_domain
 s_domain=lcase(Request.ServerVariables("SERVER_NAME"))
 if instr(1,s_domain,"qqcampus",1)>0 and instr(1,s_domain,"www",1)=0 then
  Response.Status="301 Moved Permanently"
  Response.AddHeader "Location", "http://www.qqcampus.org"
  Response.End
 end if
%>

网摘:

评论用免费asp空间做301重定向:

GlobeTour欢迎您参与讨论,请在这里发表您的看法、交流您的观点。

用免费asp空间做301重定向 Powered By Z-Blog 漫步浪尖