您的位置:首页 > 编程语言 > ASP

ASP.NET网站如何实现不同域名解析不同的子目录

2016-01-25 16:15 615 查看
准备在自己的主机里引用多个域名,先找点资料

著作权归作者所有。

商业转载请联系作者获得授权,非商业转载请注明出处。

作者:玉成

链接:https://www.zhihu.com/question/26014907/answer/31856727

来源:知乎

这是一段很有用的代码,和绑定多域名的ASP代码类似,如果你只有一个PHP空间,而你又想放置多个多个站点,下面这些代码可以帮到你

第一个:程序代码

if($HTTP_HOST=="www.nuobg.com"){

Header("Location: index.htm");

}

elseif($HTTP_HOST=="www.jwzjs.com"){

Header("Location: wiljwzjs.htm");

}

else{

Header("Location: other.htm");

}

第二个:程序代码

if($HTTP_HOST=="www.nuobg.com"){

require "moon.htm";

}

elseif($HTTP_HOST=="www.jwzjs.com"){

require "williamlong.htm";

}

else{

require "other.htm";

}

二用JS来实现多域名的跳转
<script>try {if( self.location == "http://玉米一/" ) {

top.location.href = "http://玉米一/目录";

}

else if( self.location == "http://玉米二/" ) {

top.location.href = "http://玉米二/目录";

}

else if( self.location == "http://玉米三/" ) {

top.location.href = "http://玉米三/目录";

}

else if( self.location == "http://玉米四/" ) {

top.location.href = "http://玉米四/目录";

}

else {document.write ("错误的访问地址")}} catch(e) {}</script>


下面的是ASP的代码,你可以考虑一下:

如果只有一个ASP空间,而你又想放置多个多个站点,这些代码可以帮到你
第一个 程序代码
<%

if Request.ServerVariables("SERVER_NAME")="www.nuobg.com" then

response.redirect "blog/index.asp"

else

response.redirect "index2.asp"

end if

%>

第二个程序代码

<%

select case request.servervariables("http_host")

case "www.nuobg.com" '1

Server.Transfer("v3.htm")

case "www.jwzjs.com" '2

Server.Transfer("i.htm")

case "www.abcwj.com" '3

Server.Transfer("write100.htm")

...... 继续添加 ......

end select

%>
第三个程序代码

<%

if instr(Request.ServerVariables("SERVER_NAME"),"www.nuobg.com")>0 then

response.redirect "index.asp"

elseif instr(Request.ServerVariables("SERVER_NAME"),"www.jwzjs.com")>0 then

response.redirect "x/index.asp"

elseif instr(Request.ServerVariables("SERVER_NAME"),"www.abcwj.com")>0 then

response.redirect "index3.asp"

end if

%>
第四个
程序代码

<%

if Request.ServerVariables("SERVER_NAME")="www.nuobg.com" then

response.redirect "index1.asp"

elseif Request.ServerVariables("SERVER_NAME")="www.jwzjs.com" then

response.redirect "index2.asp"

elseif Request.ServerVariables("SERVER_NAME")="www.abcwj.com" then

response.redirect "index3.asp"

end if

%>
第五个程序代码
<%

if Request.ServerVariables("SERVER_NAME")="www.nuobg.com" then

Server.Transfer("williamlong.htm")

elseif Request.ServerVariables("SERVER_NAME")="www.jwzjs.com" then

Server.Transfer("moon.htm")

elseif Request.ServerVariables("SERVER_NAME")="www.abcwj.com" then

Server.Transfer("write100.htm")

else

Server.Transfer("other.htm")

end if

%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: