asp判断网站301重定向
301重定向一般用于网站改版,或者转发中。301转发对于搜索引擎来讲是一种最有益的转发。对于自己的网站我们可以很清楚是用的URL转发功能还是301功能,但对于别人的网站我们很难直接分辨出来。下面我们来看一下如何用ASP脚本语言来判断301转发的状态。
代码如下:
<%
response.expires=0
response.addHeader "pragma","no-cache"
response.addHeader "Cache-Control","no-cache, must-revalidate"
url=lcase(request.QueryString("url"))
%>
<html><head></head><body><form method="get">
<input type="text" name="url" value="<%=url%>" size="40"/><input type="submit" value="查询状态" />
</form>
<%
call gethttpstat(url)
function gethttpstat(urlstr)
on error resume next
dim xmlhttp,webState,url2
if urlstr="" then exit function
if left(urlstr,5)<>"http:" then urlstr="http://" & urlstr
if instr(8,urlstr,"/")=0 then urlstr=urlstr & "/"
set xmlhttp=server.CreateObject("WinHttp.WinHttpRequest.5.1")
xmlhttp.SetTimeouts 10000,10000,10000,10000
xmlhttp.Option(6)=0
xmlhttp.open "GET",urlstr,False
xmlhttp.send
webState=xmlhttp.Status
if err.number<>0 then webState=err.Description
result= "<font color=red>" & urlstr & "</font> --> <font color=blue>" & webState & "</font><br>"
response.Write result
if webState="301" or webState="302" then
xxx=xmlhttp.getResponseHeader("Location")
call gethttpstat(xxx)
end if
set xmlhttp=nothing
end function
%>
</body></html>
上传至服务器运行即可实现在线检测。
更新时间:2010-6-13
|