博主呓语:

PHP、ASP、JS域名判断跳转

Posted by 破冰 on 2013-2-26 12:45 Tuesday
一、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>

评论:

WP大事记     2013-02-26 13:01   回复 2楼
太及时了,正需要这个,还有细问题QQ请教你
山寨吧     2013-02-26 12:50   回复 1楼
这个收藏了
破冰   2013-02-27 09:08 回复
@山寨吧:这个代码很实用~

发表评论: