zoukankan      html  css  js  c++  java
  • 一个空间绑定多个域名实现自动跳转的几种方法!

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

    第一个

    程序代码

    <%
    if Request.ServerVariables("SERVER_NAME")="www.dzhai.com" then
    response.redirect "williamlong/index.htm"
    else
    response.redirect "index2.htm"
    end if
    %>



    第二个

    程序代码

    <%
    select case request.servervariables("http_host")
    case "www.dzhai.com" '1
    Server.Transfer("v3.htm")
    case "www.6id.net" '2
    Server.Transfer("i.htm")
    case "www.write100.com" '3
    Server.Transfer("write100.htm")
    ...... 继续添加 ......
    end select
    %>




    第三个


    程序代码

    <%
    if instr(Request.ServerVariables("SERVER_NAME"),"www.dzhai.com")>0 then
    response.redirect "index.asp"
    elseif instr(Request.ServerVariables("SERVER_NAME"),"www.6id.net")>0 then
    response.redirect "x/index.asp"
    elseif instr(Request.ServerVariables("SERVER_NAME"),"www.write100.com")>0 then
    response.redirect "index3.asp"
    end if
    %>




    第四个


    程序代码

    <%
    if Request.ServerVariables("SERVER_NAME")="www.dzhai.com" then
    response.redirect "index1.asp"
    elseif Request.ServerVariables("SERVER_NAME")="www.6id.net" then
    response.redirect "index2.asp"
    elseif Request.ServerVariables("SERVER_NAME")="www.write100.com" then
    response.redirect "index3.asp"
    end if
    %>



    第五个


    程序代码

    <%
    if Request.ServerVariables("SERVER_NAME")="www.dzhai.com" then
    Server.Transfer("williamlong.htm")
    elseif Request.ServerVariables("SERVER_NAME")="www.6id.net" then
    Server.Transfer("moon.htm")
    elseif Request.ServerVariables("SERVER_NAME")="www.write100.com" then
    Server.Transfer("write100.htm")
    else
    Server.Transfer("other.htm")
    end if
    %>





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

    第一个:


    程序代码

    if($HTTP_HOST=="www.dzhai.com"){
    Header("Location: moon.htm");
    }
    elseif($HTTP_HOST=="www.6id.net"){
    Header("Location: williamlong.htm");
    }
    else{
    Header("Location: other.htm");
    }




    第二个:

    程序代码

    if($HTTP_HOST=="www.dzhai.com"){
    require "moon.htm";
    }
    elseif($HTTP_HOST=="www.6id.net"){
    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>



    详解:

    1:首先,你的空间必须支持ASP,并且这个空间可以绑定下面所用到的两个域名,然后新建一个ASP

    的首页文件,这个ASP文件中的代码这么写:
    <%if Request.ServerVariables("SERVER_NAME")="XXXX.cn" then '第一个输入的网址
    response.redirect "index.html"                               '将它转发到相应的文件夹
    else%>

    <%end if%>
    <%if Request.ServerVariables("SERVER_NAME")="www.XXXX.cn" then response.redirect

    "index.html"                
    else%>
    <%end if%>

    <%if Request.ServerVariables("SERVER_NAME")="XXXX.cn" then   '第二个输入的网址
    response.redirect "soft/index.html"                               '将它转发到相应的文件


    else%>

    <%end if%>

    <%if Request.ServerVariables("SERVER_NAME")="www.XXXX.cn" thenresponse.redirect

    "soft/index.html"
    else%>

    <%end if%>

    2:写好后将这个文件存储为index.asp ,也就是要做你的首页。不用担心,这个是不会显示的。这

    个就是自动识别访问者输入域名的,然后依据访问者输入的地址进行自动跳转的。跳转是在瞬间完

    成的,你是看不到的。呵呵

    3.现在要做的就是把你空间中建立两个不同的文件夹了,分别做为两个网站的目录。比如一个放音

    乐的cd文件夹。一个放FLASH动画的flash夹件夹。里面的内容自己放!
    4.开始上传刚才做的index.asp文件吧!把index.asp文件上传到空间根目录下。
    5.去你的空间中将两个域名都进行绑定好,然后就可以测试了。

    申明

    非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

    博文欢迎转载,但请给出原文连接。

  • 相关阅读:
    mac 安装mysql. 使用brew install mysql 报错
    当忙碌成为借口的时候
    MySQL数据库导入导出详解[转发]
    一些模拟浏览器自动Post到服务器的工具(备忘)
    [转]一句css代码让你的网站变灰,一起悼念地震中逝去的生命!
    MYSQL命令行常用操作
    国外达人收集的Cheet Sheet
    SQL Server:将6字节的十六进制页面号转化成【文件号:页面号】格式函数
    javaWEB核心
    电商
  • 原文地址:https://www.cnblogs.com/Athrun/p/1452865.html
Copyright © 2011-2022 走看看