大家好,我是久诺网络的程序员,网站上线三天,发现被google收录了,但是网址都是不带www的,才想起来没有把不带www的网址转发到带www的。于是就去域名管理面板去设置,又发现了一个问题,域名商最近都关掉了域名转发功能,什么时候恢复还不知道呢。怎么办呢?那只有做301转向了,首先虚拟主机得支持301转向,然后给要转发的页面在顶部加上一段代码吗,我们这里说的是针对asp的代码:
<%
if request.ServerVariables("HTTP_HOST")="nuool.com" then
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location","http://www.nuool.com"
Response.End
end if
%>
发现首页跳转正常,但是被收录的内页也被跳转到首页了,于是再对代码进行改进:
<% dim kk
if request.ServerVariables("HTTP_HOST")="nuool.com" then
if Request.ServerVariables("QUERY_STRING") <>"" then kk="?"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location","http://www.nuool.com"& kk & Request.ServerVariables("QUERY_STRING")
Response.End
end if
%>
这一下内页跳转正常,但是发现如果用nuool.com打开时候,跳转到http://www.nuool.com/index.asp 也就是带上了点尾巴,所以还是要进行修改,以下就是
改好的代码
<%
dim aurl
if request.ServerVariables("HTTP_HOST")="nuool.com" then
if Request.ServerVariables("QUERY_STRING") ="" then
aurl="http://www.nuool.com"
else aurl="http://www.nuool.com" & "?" & Request.ServerVariables("QUERY_STRING")
end if
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location",aurl
Response.End
end if
%>
这样就可以了,301定向完成了。希望这小小程序能给大家带来帮助。网站建设请联系:久诺网络,专业品质!0570-8885048