一、什么是301重定向,301重定向是什么意思
301重定向是一种非常重要的“自动转向”技术。网址重定向最为可行的一种办法。当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码的一种,表示本网页永久性转移到另一个地址。
二、如何用ASP来编写301重定向代码
将以下代码放在每个asp页面的头部即可。
<% Function GetUrl()
Dim ScriptAddress,Servername,qs
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME"))
Servername = CStr(Request.ServerVariables("Server_Name"))
qs=Request.QueryString
if qs<>"" then
GetUrl ="http://"& Servername & ScriptAddress &"?"&qs
else
GetUrl ="http://"& Servername & ScriptAddress
end if
End Function
dim urlstr,a,b,oldurl,c
urlstr=GetUrl
oldurl=GetUrl
urlstr=replace(urlstr,"http://","")
a=instr(urlstr,"/")
if a>0 then
urlstr=left(urlstr,a)
end if
urlstr=replace(urlstr,"/","")
b=lcase(urlstr)
if b<>"www.128sj.com" then
c=replace(oldurl,"http://" & b,"")
response.redirect "https://www.128sj.com" & c
end if
%>
以上代码其实并不难看懂,Function GetUrl()这个过程是获取用户所访问的当前URL地址,下面是对URL进行判断,如果不是www.128sj.com域名下的地址,就把url中的域名改成www.128sj.com,如果是的话,就终止这段代码!www.128sj.com这个地址只是一个地址的举例,用户可以根据的需要改成任何地址。
本文标题:在【免费空间】中如何用ASP来编写301重定向代码
本文地址:https://www.128sj.com/jiaocheng/201903082437.html,转载请注明出处