301是优化的必备步骤之一,让不带www的域名跳转到带www的域名上,从而增加带www域名的权重(减少分权)。然而部分空间是不支持301跳转的,为此在科汛CMS程序中开发出ASP版完美301跳转。
只需修改一处asp文件/Conn.asp,在文件开头加上跳转代码如下:
<%
'========301跳转开始========
Dim An_Jump,An_Static
An_Jump=True '是否开启301跳转 开启: True 关闭: False
An_Static=False '是否开启伪静态 开启: True 关闭: False
If Lcase(Left(Request.ServerVariables("Server_name"),3))<>"www" and An_Jump Then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", GetUrl
Response.End
End If
'Response.Write GetUrl '测试url
Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "https://"
Else
strTemp = "https://"
End If
If Lcase(Left(Request.ServerVariables("Server_name"),3))<>"www" Then
strTemp = strTemp&"www."
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then
strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
end if
If An_Static Then
Dim id,page,m,d,n
id=Request.QueryString("id")
page=Request.QueryString("page")
m=Request.QueryString("m")
d=Request.QueryString("d")
n=Request.QueryString("n")
If id<>"" Then
If page<>"" Then
strTemp = strTemp & "/list-"&id&"-"&page&".html"
Else
strTemp = strTemp & "/list-"&id&".html"
End If
End If
If m<>"" and d<>"" Then
strTemp = strTemp & "/thread-"&d&"-"&m&".html"
End If
If n<>"" Then
strTemp = strTemp & "/plus/tags.asp?n="&n
End If
Else
strTemp = strTemp & Replace(Request.ServerVariables("URL"),"index.asp","")
If Trim(Request.QueryString) <> "" Then
strTemp = strTemp & "?" & Trim(Request.QueryString)
end if
End If
GetUrl = strTemp
End Function
'========301跳转结束========
%>