首页 > 代码库 > js实现域名判断后跳转到指定网址

js实现域名判断后跳转到指定网址

js实现域名判断后跳转到指定网址,也适用于同一虚拟空间放多个网站:

<script>
       try
           {
               if(self.location == "http://apple.ya37.com/")
               {
                   top.location.href =http://www.mamicode.com/ "http://ya37.com/apple/";
               }
               else if(self.location == "http://girl.ya37.com/")
               {
                   top.location.href = "http://ya37.com/girl/";
               }
               else if(self.location == "http://simple.ya37.com/")
               {
                   top.location.href = "http://ya37.com/simple/";
               }
               else {document.write ("错误的访问地址")}
           }
       catch(e){ }
   </script>

看明白了吧,如果访问者输入的域名是"http://apple.ya37.com/"的话,就访问"http://ya37.com/apple/"

js实现域名判断后跳转到指定网址