Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26188116
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: 系统运维

2009-11-19 13:05:25

ASP:
1.使用CASE语句,缺点:同一域名即@和www需要两次循环,代码显重复
<%
host=lcase(request.servervariables("HTTP_HOST"))
select CASE host
CASE ""
 response.redirect "index.htm"
CASE "abc.com"
 response.redirect "index.htm"

CASE ELSE
 response.redirect "other.htm"
END select
%>
--------------------------
<%if instr(Request.ServerVariables
("SERVER_NAME"),"kekexi.com")>0 then
response.redirect "index.asp"
else if instr(Request.ServerVariables
("SERVER_NAME"),"4668.com")>0 then
response.redirect "x/index.asp"
else if instr(Request.ServerVariables
("SERVER_NAME"),"web315.com")>0 thenr
esponse.redirect "index3.asp"
end if
end if

-----------------------
<%if Request.ServerVariables("SERVER_NAME")="" then
response.redirect "zkj"
else
response.redirect "i.htm"
end if%>

----------------------------
<%if Request.ServerVariables("SERVER_NAME")="" then
response.redirect "index1.asp"
else if Request.ServerVariables("SERVER_NAME")="" then
response.redirect "index2.asp"
else if Request.ServerVariables("SERVER_NAME")="" then
response.redirect "index3.asp"
end if
end if
end if%>
 
 

2.为解决上述问题,可以加条件判断加上www. 这样就可以自动识别www前缀:
<%
dim domain
domain=request.ServerVariables("Server_Name")
if instr(domain,"www.") then domain=right(domain,len(domain)-4)
if domain="abc.com" then
 response.redirect "1/"
elseif domain="123.com" then
 response.redirect "2/"
else
 response.redirect "3/"
end if
%>

3.

====================================
PHP:
1.多个
$domain_net="abc.com";
$dot_net_url="目录1/";
$dot_com_url="目录2/";
if(($HTTP_HOST=="$domain_net")or($HTTP_HOST==""))
{
Header("Location: $dot_net_url");
}
else
{
Header("Location: $dot_com_url");
}
?>
switch ($_SERVER["HTTP_HOST"]) {
case "ychon.org":
header("location:bbs");
break;
default:
header("location:news");
break;
}
?>

2.单个
Header("Location: [url]");
?>
或:
echo "";
?>
还可以这样用:
header("refresh:3;url=");
?>
注意:使用Header函数时必须网页未产生任何输出,此时尤其要注意空格的问题。即必须放在网页最开始处。

====================================
Java Script :


-------------------------------------


location对象有以下几个属性:

hash 设置或获取 href 属性中在井号“#”后面的分段。
host 设置或获取 location 或 URL 的 hostname 和 port 号码。
hostname 设置或获取 location 或 URL 的主机名称部分。
href 设置或获取整个 URL 为字符串。
pathname 设置或获取对象指定的文件名或路径。
port 设置或获取与 URL 关联的端口号码。
protocol 设置或获取 URL 的协议部分。
search 设置或获取 href 属性中跟在问号后面的部分。
阅读(1450) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~