[转帖][经典代码]多域名绑定同一空间的asp,php,Javascript代码
如果你有多个域名,想绑定到同一个空间的不同目录。如果你的空间商提供这个服务,那就简单了,但是大部分空间商,并不支持这种服务。多个域名榜定到一个空间,与其浪费域名资源,不如用代码实现多域名到同一空间的绑定。当然,效果虽然不是特别的好,但是看起来也不赖。下面是asp,php,javascripts的代码,都可以实现多域名绑定同一空间。很经典、实用。<P>asp代码</P>
<P>------------------</P>
<P><% <BR>'取得HTTP输入的值并付值到HTOST中 <BR>host=lcase(request.servervariables("HTTP_HOST")) <BR>'开始条件跳转 <BR>SELECT CASE host <BR>' 如果HOST的值是www.iswind.net就选择事件case"www.iswind.net"的命令 <BR>CASE "www.abc.net" <BR>' Below is the redirect command <BR>response.redirect "web/" <BR>CASE "www.efd.com" <BR>response.redirect "web1/" <BR>'We use CASE ELSE to fix any other requests <BR>CASE ELSE <BR>response.redirect "web1/" <BR>END SELECT <BR>%> <BR><BR></P>
<P>PHP代码</P>
<P>------------------<BR><?php <BR>$domain_net="yeahe.com"; <BR>$dot_net_url="bbs/"; <BR>$dot_com_url="flash"; <BR>if(($HTTP_HOST=="$domain_net")or($HTTP_HOST=="www.$domain_net")) <BR>{ <BR>Header("Location: $dot_net_url"); <BR>} <BR>else <BR>{ <BR>Header("Location: $dot_com_url"); <BR>} <BR>?> </P>
<P>Javascript代码</P>
<P>------------------<BR><script>try { if( self.location == "http://玉米一/" ) { <BR>top.location.href = "http://玉米一/目录"; <BR>} <BR>else if( self.location == "http://玉米二/" ) { <BR>top.location.href = "http://玉米二/目录"; <BR>} <BR>else if( self.location == "http://玉米三/" ) { <BR>top.location.href = "http://玉米三/目录"; <BR>} <BR>else if( self.location == "http://玉米四/" ) { <BR>top.location.href = "http://玉米四/目录"; <BR>} <BR>else { document.write ("错误的访问地址") } } catch(e) { }</script> </P>
<P>------------------------------------</P>
<P>上述代码由落伍者论坛的go8 提供,原始地址为 http://www.im286.com/viewthread.php?tid=820865</P>
<P>-----------------------------------</P>
<P>本站使用的演示效果:</P>
<P>首先,解析 www.gegou.com 和 www.evoleo.com 到同一个空间;</P>
<P>目的是,需要浏览者输入www.evoleo.com 和 evoleo.com 的时候访问网站目录blog下的内容.大家可以点前面的连接,看看效果。实现代码如下:</P>
<P><script>try { if( self.location == "http://evoleo.com/" ) {<BR>top.location.href = "http://evoleo.com/blog/";<BR>}<BR>else if( self.location == "http://www.evoleo.com/" ) {<BR>top.location.href = "http://www.evoleo.com/blog/";<BR>}<BR>else { document.write ("错误的访问地址") } } catch(e) { }</script></P><BR> <P>偶的应用:</P>
<DIV class=quote><script>try { if( self.location == "http://www.sybasebbs.com/" ) {<br>top.location.href = "http://www.sybasebbs.com/index.html";<br>}<br>else if( self.location == "http://www.dbabbs.com/" ) {<br>top.location.href = "http://www.dbabbs.com/indexdba.html";<br>}<br>else { <br>top.location.href = "http://www.sybasebbs.com/index.html";<br>} } catch(e) { }</script></DIV>
<P>把这段内存保存成HTM文件,让IIS最先调用。</P>
[此贴子已经被作者于2005-9-2 17:00:49编辑过]
页:
[1]