余峰 中国好声音视频:请问关于域名跳转的问题

来源:百度文库 编辑:高考问答 时间:2024/04/29 01:07:55
将以下代码保存为index.htm,放到根目录下即可

<script language="javascript">
if(location.toString()=="http://www.aaa.com/index.htm")
{
location.href="aaa/index.htm"
}
</script>
<meta http-equiv="refresh" content="3;URL=bbb/index.htm" />
三秒后将跳转到站点b

其中location.toString是取得IE的当前地址
location.href是跳转到指定地址

请问,
现在的情况是判断地址栏是否输入了http://www.aaa.com,如果是,就跳转

如果我在地址栏输入了aaa.com或者www.aaa.com,还能判断真假么?

如果不能,源码应该怎样修改一下呢?

if(location.toString().indexOf("www.aaa.com")!= -1)
{
location.href="aaa/index.htm"
}

意思是如果URL包含www.aaa.com则跳转
indexOf()是查找字符在原字符串中的位置,若不存在则返回-1

<script language="javascript">
if(location.toString()=="aaa.com")
{
location.href="aaa/index.htm"

<%'数据库连接,存放用户注册信息,内容为域名,以及域名所指向的具体URL地址,域名访问简单记数,以及一些用户信息%>
<!--#include file="conn.asp" -->
<%
'获取URL参数
url=request.QueryString("url")
'判断是否是以虚拟@域名形式传递过来
if instr(url,"@")=0 then
'如果没有则直接跳转到自己的首页index1.asp
response.Redirect("index1.asp")
else
'处理url参数,取得http://username@domain.com中的username
url=right(url,(len(url)-len("http://")))
url=left(url,(instr(url,"@")-1))
user=url
'从数据库中取出于username对应的转向目标url地址
set rs=conn.execute("select siteurl from url where user='"&user&"'")
if rs.bof or rs.eof then
'如果没有记录则显示:该域名不存在
response.Write("<a href='http://skyworm.com'><font size=2><center>该域名不存在</center></font></a>")
else
'对域名访问率简单记数
conn.execute("update url set count=count+1 where user='"&user&"'")
'跳转到虚拟域名对应的目标url地址,程序结束!
response.Redirect(rs(0))
end if
rs.close
set rs=nothing
end if
conn.close
set conn=nothing
%>