【深圳網(wǎng)站建設(shè)】ASP怎么實現(xiàn)301重定向
為什么要使用301重定向?
答:使用301重定向可以把不帶www的域名轉(zhuǎn)向帶www的域名,這樣可以把權(quán)重全部指向帶有www的域名,對網(wǎng)站優(yōu)化很有幫助。
怎么在代碼中實現(xiàn)301重定向?
答:在數(shù)據(jù)庫連接文件里加入以下代碼即可實現(xiàn)。
<%
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
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
%>
本文來自:深圳網(wǎng)站建設(shè) http://tjdzrhy.com