域名判断后跳转三种办法——PHP跳转代码_ASP跳转代码_JS跳转代码

根据访问域名跳转不同目录地址的ASP、PHP、JS三种办法四个样例
一、ASP
<%
host=lcase(request.servervariables("HTTP_HOST"))
'开始条件跳转
SELECT CASE host
CASE "https://www.360docs.net/doc/be10094698.html,"
response.redirect "/blog/"
CASE "https://www.360docs.net/doc/be10094698.html,"
response.redirect "/bbs/"
case "https://www.360docs.net/doc/be10094698.html,"
response.redirect "/cyle/"
case "https://www.360docs.net/doc/be10094698.html,"
response.redirect "/cyle/"
CASE ELSE
response.redirect "/main/"
END SELECT
%>
二、PHP
情况:多个域名都指向一台服务器的同一个文件夹"NNN",要求
https://www.360docs.net/doc/be10094698.html,
https://www.360docs.net/doc/be10094698.html,
当URL为https://www.360docs.net/doc/be10094698.html,的时候,页面自动跳转到NNN文件夹里的ddd
当URL为https://www.360docs.net/doc/be10094698.html,的时候,页面自动跳转到NNN文件夹里的index.htm
代码:
$domain_net="https://www.360docs.net/doc/be10094698.html,";
$domain_com="https://www.360docs.net/doc/be10094698.html,";
$dot_net_url="bbs/";
$dot_com_url="index.html";
if(($HTTP_HOST=="$domain_net")or($HTTP_HOST=="www.$domain_net"))
{
Header("Location: $dot_net_url");
}
elseif(($HTTP_HOST=="$domain_com")or($HTTP_HOST=="www.$domain_com"))
{
Header("Location: $dot_com_url");
}
else
{
include_once('hehe.php');
}
?>

更简单的办法
//key-value 路由表
$domain_route = array(
'https://www.360docs.net/doc/be10094698.html,' => 'a/index.html',
'https://www.360docs.net/doc/be10094698.html,' => 'a/index.html', //处理www
'https://www.360docs.net/doc/be10094698.html,' => 'b/index.html',
);
//获取当前访问域名做为:key
$domain = $_SERVER['HTTP_HOST'];
//通过key-value表取出目录地址
$target_url = $domain_route[$domain];
//能过header跳转至目录地址,注意,使用header跳转需要把此段代码放至你程序代码的开始处理,执行此代码代码前,不能有任何输出内容
header("location:{$target_url}");///你可使用if ($target_url ==null) 增加空的缺省跳转,避免你的数组有漏。
?>
三、JS代码:

相关主题
相关文档
最新文档