PHP、ASP、JS域名判断跳转
一、ASP
<%
host=lcase(request.servervariables("HTTP_HOST"))
'开始条件跳转
SELECT CASE host
CASE "blog.xshell.net"
response.redirect "/blog/"
CASE "bbs.xshell.net"
response.redirect "/bbs/"
case "cyle.xshell.net"
response.redirect "/cyle/"
case "www.xshell.net"
response.redirect "/cyle/"
CASE ELSE
response.redirect "/main/"
END SELECT
%>
二、PHP
情况:多个域名都指向一台服务器的同一个文件夹"NNN",要求
www.ddd.com
www.eee.com
当URL为www.ddd.com的时候,页面自动跳转到NNN文件夹里的ddd
当URL为www.eee.com的时候,页面自动跳转到NNN文件夹里的index.htm
代码:
<?php
$domain_net="wjabc.net";
$domain_com="wjabc.com";
$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');
}
?>
三、JS代码:
<script>try {if( self.location == "http://wjabc.com/" ) {
top.location.href = "http://wjabc.com/directory";
}
else if( self.location == "http://gzcy.net/" ) {
top.location.href = "http://gzcy.net/directory";
}
else if( self.location == "http://gzzp.net/" ) {
top.location.href = "http://gzzp.net/directory";
}
else if( self.location == "http://vinzine.com/" ) {
top.location.href = "http://vinzine.com/directory";
}
else {document.write ("错误的访问地址")}} catch(e) {}</script>
<%
host=lcase(request.servervariables("HTTP_HOST"))
'开始条件跳转
SELECT CASE host
CASE "blog.xshell.net"
response.redirect "/blog/"
CASE "bbs.xshell.net"
response.redirect "/bbs/"
case "cyle.xshell.net"
response.redirect "/cyle/"
case "www.xshell.net"
response.redirect "/cyle/"
CASE ELSE
response.redirect "/main/"
END SELECT
%>
二、PHP
情况:多个域名都指向一台服务器的同一个文件夹"NNN",要求
www.ddd.com
www.eee.com
当URL为www.ddd.com的时候,页面自动跳转到NNN文件夹里的ddd
当URL为www.eee.com的时候,页面自动跳转到NNN文件夹里的index.htm
代码:
<?php
$domain_net="wjabc.net";
$domain_com="wjabc.com";
$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');
}
?>
三、JS代码:
<script>try {if( self.location == "http://wjabc.com/" ) {
top.location.href = "http://wjabc.com/directory";
}
else if( self.location == "http://gzcy.net/" ) {
top.location.href = "http://gzcy.net/directory";
}
else if( self.location == "http://gzzp.net/" ) {
top.location.href = "http://gzzp.net/directory";
}
else if( self.location == "http://vinzine.com/" ) {
top.location.href = "http://vinzine.com/directory";
}
else {document.write ("错误的访问地址")}} catch(e) {}</script>
目前有 0 条评论