ASP实现301重定向代码如下:
注:要使以下的代码能在一开始就执行,比如说在数据库连接文件里加入以下代码就可以
-----------------------------------------------
<%
Dim Server_Name,Path_infostr,Query_Stringstr
Path_infostr=lcase(request.ServerVariables("PATH_INFO"))
Server_Name=lcase(request.ServerVariables("Server_Name"))
Query_Stringstr=request.ServerVariables("Query_String")
If Query_Stringstr<>"" Then Query_Stringstr=" "&Query_Stringstr
IF instr(Server_Name,"www.")<1 Then '此处含义是实现不带www.的域名将被重定向
Response.Status = "301 Moved Permanently"
if instr(Path_infostr,"index")>0 or instr(Path_infostr,"default")>0 Then
Response.AddHeader "Location","http://www."&Server_Name
Else
Response.AddHeader "Location","http://www."&Server_Name&Path_infostr&Query_Stringstr
End if
Response.End
End if
%>
---------------------------------------------------------
以上就是ASP实现301重定向代码,有用到的朋友可以参考下