注册 登录
编程论坛 ASP技术论坛

发一下我用的cms系统的301跳转代码

yingwu55 发布于 2012-09-06 15:42, 416 次点击
做前端的,本来对这些就是一知半解的,参照了一些代码,测试后可用
这里主要是让不熟悉代码的童鞋把不同的网址结构的跳转处理好
下面是我参照的代码(不符合我的网址结构,但符合大多数asp的网址结构)
<%
'修改,301定向到主域名
Dim strHOST,goURL
strHOST = LCase(Request.ServerVariables("HTTP_HOST"))'域名转换为小写
if Request.ServerVariables("QUERY_STRING")<>"" then '含有参数则
   goURL="www.("QUERY_STRING")&"#from301="&strHOST
else   '不含参数则
   goURL="www.
end if
  if strHOST<>"www. then  '域名不是则
    Response.Status = "301 Moved Permanently"
    Response.AddHeader "Location",goURL
    Response.End
  else        
  end if
%>


修改后的代码(可用)

<%
if request.ServerVariables("HTTP_HOST")<>"www. then
if Request.ServerVariables("SCRIPT_NAME")="/?main.html" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","www.
else
if Request.ServerVariables("QUERY_STRING")<>"" then
p="/?"
else
p=""
end if
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","$.

("QUERY_STRING")
Response.End
end if
end if
%>
1 回复
#2
yingwu552012-09-06 15:43
案例站点
http://www.
'修改,301定向到主域名
Dim strHOST,goURL
strHOST = LCase(Request.ServerVariables("HTTP_HOST"))'域名转换为小写
if Request.ServerVariables("QUERY_STRING")<>"" then '含有参数则
   goURL="www.("QUERY_STRING")&"#from301="&strHOST
else   '不含参数则
   goURL="www.
end if
  if strHOST<>"www. then  '域名不是则
    Response.Status = "301 Moved Permanently"
    Response.AddHeader "Location",goURL
    Response.End
  else        
  end if
%>


修改后的代码(可用)

<%
if request.ServerVariables("HTTP_HOST")<>"www. then
if Request.ServerVariables("SCRIPT_NAME")="/?main.html" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","www.
else
if Request.ServerVariables("QUERY_STRING")<>"" then
p="/?"
else
p=""
end if
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","$.

("QUERY_STRING")
Response.End
end if
end if
%>
1