WenRou's Blog

新浪微薄腾讯微薄

最新碎语:测试图片碎语哦

您的位置:WenRou's Blog >分享> 多个域名指向同一空间不同目录,文件(js.jsp.php.asp)

多个域名指向同一空间不同目录,文件(js.jsp.php.asp)

多个域名指向同一空间不同目录,文件(js.jsp.php.asp) <span style="color: red;">附注:经过本人测试 js可以实现这个功能,而又asp和php均没有成功!!!</span> JS实现多域名同一空间不同目录的代码: <script>// <![CDATA[           url=window.location.href           if(url.indexOf(&#34;happy01.cn&#34;)!=-1)           location=&#34;movie&#34;           if(url.indexOf(&#34;cothurn.com&#34;)!=-1)           location=&#34;blog&#34;           if(url.indexOf(&#34;wenrou.cn&#34;)!=-1)           location=&#34;index.html&#34; // ]]></script> php实现多域名同一空间不同目录的代码: <!--p<br-->$domain1="wenrou.cn"; $domain2="happy01.cn"; $domain3="cothurn.com"; $dot1="index.html"; $dot2="movie"; $dot3="blog"; if(($HTTP_HOST=="$domain1")or($HTTP_HOST=="www.$domain1")) { Header("Location: $dot1"); } elseif(($HTTP_HOST=="$domain2")or($HTTP_HOST=="www.$domain2")) { Header("Location: $dot2"); } else(($HTTP_HOST=="$domain3")or($HTTP_HOST=="www.$domain3")) { Header("Location: $dot3"); } ?&gt; JSP实现多域名同一空间不同目录的代码: <script type="text/javascript">// <![CDATA[ try { if( self.location == &#34;http://www.wenrou.cn/&#34; ) { top.location.href = &#34;http://www.wenrou.cn/index.html&#34;; } else if( self.location == &#34;http://www.happy01.cn/&#34; ) { top.location.href = &#34;http://www.happy01.cn/movie&#34;; } else if( self.location == &#34;http://www.cothurn.com/&#34; ) { top.location.href = &#34;http://www.cothurn.com/blog&#34;; } else { document.write (&#34;404.html&#34;) } } catch(e) { } // ]]></script> ASP实现多域名同一空间不同目录的代码: 解决方案一(case) <!--r /> host=lcase(request.servervariables(&#34;HTTP_HOST&#34;)) Sel&#101;ct CASE host CASE &#34;www.wenrou.cn&#34; response.redirect&#34;index.html&#34; CASE &#34;wenrou.cn&#34; response.redirect&#34;index.html&#34; CASE &#34;www.happy01.cn&#34; response.redirect&#34;movie/&#34; CASE &#34;happy01.cn&#34; response.redirect&#34;movie/&#34; CASE &#34;www.cothurn.com&#34; response.redirect&#34;blog/&#34; CASE &#34;cothurn.com&#34; response.redirect&#34;blog/&#34; CASEELSE response.redirect&#34;404.html&#34; END Sel&#101;ct --> 解决方案二(if) <!-- Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;www.wenrou.cn&#34; then response.redirect &#34;index.html&#34; elseif Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;www.happy01.cn&#34; response.redirect &#34;movie&#34; else Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;www.cothurn.com&#34; response.redirect &#34;blog&#34; end i--> 解决方案三(Transfer)完全隐藏式,这个很好 <!--r /> sel&#101;ct case request.servervariables(&#34;http_host&#34;) case &#34;www.wenrou.cn&#34; &#39;1 Server.Transfer(&#34;index.html&#34;) case &#34;www.happy01.cn&#34; &#39;2 Server.Transfer(&#34;movie&#34;) case &#34;www.cothurn.com&#34; &#39;3 Server.Transfer(&#34;blog&#34;) end sel&#101;ct --> 解决方案四(instr) <!-- instr(Request.ServerVariables (&#34;SERVER_NAME&#34;),&#34;wenrou.cn&#34;)>0 then response.redirect &#34;index.html&#34; elseif instr(Request.ServerVariables (&#34;SERVER_NAME&#34;),&#34;happy01.cn&#34;)>0 then response.redirect &#34;movie&#34; else instr(Request.ServerVariables (&#34;SERVER_NAME&#34;),&#34;cothurn.com&#34;)>0 then response.redirect &#34;blog&#34; end if --> 单空间多域名转向目录代码javascript 发布时间:2009-4-5 | 浏览次数:644 为了方便站长实现网站多域名功能。从而实现一个虚拟主机空间里的网站栏目增加二级域名或一级域名功能。也可以为一些小型企业建站服务单位降低空间成本,实现一个虚拟主机空间多个网站的功能,而有互不影响,现将代码提供如下: 首先,将域名解析做好,要与你挂目录的空间一致才行,如果服务器上有多个网站,是通过主机头指向的,那么你要将你放目录的网站主机头设为默认,然后在你放目录的主机头的首页文件加入下面代码的任何一种,就可以了。 第一个 程序代码 <!--r /> if Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;www.dlstu.cn&#34; then response.redirect &#34;/bbs/&#34; else response.redirect &#34;/blog/&#34; end if --> 第二个 程序代码 <!--r /> sel&#101;ct case request.servervariables(&#34;http_host&#34;) case &#34;www.dlstu.cn&#34; Server.Transfer(&#34;/bbs/&#34;) case &#34;bbs.dlstu.cn&#34; Server.Transfer(&#34;/bbs/&#34;) case &#34;blog.dlstu.cn&#34; Server.Transfer(&#34;/blog/&#34;) ...... 继续添加 ...... end sel&#101;ct --> 第三个 程序代码 <!--r /> if instr(Request.ServerVariables(&#34;SERVER_NAME&#34;),&#34;dlstu.cn&#34;)>0 then response.redirect &#34;/bbs/&#34; elseif instr(Request.ServerVariables(&#34;SERVER_NAME&#34;),&#34;dlstu.com&#34;)>0 then response.redirect &#34;/bbs/&#34; elseif instr(Request.ServerVariables(&#34;SERVER_NAME&#34;),&#34;h11.cn&#34;)>0 then response.redirect &#34;bbs/&#34; end if --> 第四个 程序代码 <!--r /> if Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;www.dlstu.cn&#34; then response.redirect &#34;/bbs/index.asp&#34; elseif Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;www.dlstu.com&#34; then response.redirect &#34;/bbs/index.asp&#34; elseif Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;bbs.163.com&#34; then response.redirect &#34;/bbs/index.asp&#34; end if --> 第五个 程序代码 <!--r /> &#39;取得HTTP输入的值并付值到HTOST中 dim host host=lcase(request.servervariables(&#34;HTTP_HOST&#34;)) ‘开始条件跳转 Sel&#101;ct CASE host &#39; 如果HOST的值是www.dlstu.cn就选择事件case www.dlstu.cn的命令 CASE www.dlstu.cn &#39;直接跳转 response.redirect &#34;/bbs/&#34; CASE www.dlstu.com response.redirect &#34;/blog/&#34; &#39;其它域名跳转 CASE ELSE response.redirect &#34;/blog/&#34; END Sel&#101;ct --> 第六个 程序代码 <!--r /> from=lcase(Request.ServerVariables(&#34;HTTP_HOST&#34;)) if left(from,4)=&#34;www.&#34; then Response.redirect(&#34;index.asp&#34;) &#39;此处为网站首页地址 else response.Write( &#34;/bbs/&#34;) end if --> 这个呢~~也是支持多域名绑定的,非主机头绑定,当然,也是某个域名泛解析到服务器最好的选择:)Oblog用的就是这种跳转。 第七个 用JS实现泛玉米解析 location对象有以下几个属性: hash 设置或获取 href 属性中在井号“#”后面的分段。 host 设置或获取 location 或 URL 的 hostname 和 port 号码。 hostname 设置或获取 location 或 URL 的主机名称部分。 href 设置或获取整个 URL 为字符串。 pathname 设置或获取对象指定的文件名或路径。 port 设置或获取与 URL 关联的端口号码。 protocol 设置或获取 URL 的协议部分。 search 设置或获取 href 属性中跟在问号后面的部分。 因此。我们就可以根据玉米的不同实现跳转不同的目录,具体代码: 程序代码 <script>// <![CDATA[ switch (window.location.hostname) { case &#34;test&#34; ://确定玉米为TEST window.location.pathname=&#34;1&#34;//跳转到1目录 break; case &#34;127.0.0.1&#34; ://确定玉米为127.0.0.1 window.location.pathname=&#34;2&#34;//跳转到2目录 break; //依次类推写下去 default ://如果没有找到该玉米 window.location.pathname=&#34;3&#34;//跳转到3目录 } // ]]></script> 不支持泛解析虚拟主机绑定多域名的ASP代码 如果有有一个ASP空间,而你又想放置多个多个站点或DOMAIN,这些代码可以帮到你 第一个 <!-- Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;www.netbei.com&#34; then response.redirect &#34;zkj&#34; else response.redirect &#34;i.htm&#34; end i--> 第二个 <!--r /> sel&#101;ct case request.servervariables(&#34;http_host&#34;) case &#34;www.netbei.com&#34; Server.Transfer(&#34;v3.htm&#34;) case &#34;www.aspcn.net&#34; &#39;2 Server.Transfer(&#34;i.htm&#34;) case &#34;www.netbei.cn&#34; &#39;3 Server.Transfer(&#34;netbei.htm&#34;) &#39;...... 继续添加 ...... end sel&#101;ct --> 第三个 <!-- instr(Request.ServerVariables (&#34;SERVER_NAME&#34;),&#34;kekexi.com&#34;)>0 then 6 response.redirect &#34;index.asp&#34; else if instr(Request.ServerVariables (&#34;SERVER_NAME&#34;),&#34;4668.com&#34;)>0 response.redirect &#34;x/index.asp&#34; else if instr(Request.ServerVariables (&#34;SERVER_NAME&#34;),&#34;web315.com&#34;)>0 thenr esponse.redirect &#34;index3.asp&#34; end if end if end i--> 第四个 <!-- Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;www.netbei.com&#34; then response.redirect &#34;index1.asp&#34; else if Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;www.cike.org&#34; then response.redirect &#34;index2.asp&#34; else if Request.ServerVariables(&#34;SERVER_NAME&#34;)=&#34;www.163.com&#34; then response.redirect &#34;index3.asp&#34; end if end if end i--> 第二种方法: <!--r /> dim domainname,result domainname=Request.ServerVariables(&#34;SERVER_NAME&#34;) result=right(domainname,12) if result=&#34;my.netbei.com&#34; then --> <!--#include file=mynetbei.asp --> <!--r /> Elseif result=&#34;rtisancn.com&#34; then --> <!--#include file=artisan.asp --> <!--r /> Elseif result=&#34;gn.netbei.com&#34; then --> <!--#include file=web.asp --> <!--r /> Elseif result=&#34;.forwest.com&#34; then --> <!--#include file=forwest_com.asp --> <!--r /> Else --> <!--#include file=netbei.asp --> <!--r /> End if -->

---

转载请注明本文标题和链接:《多个域名指向同一空间不同目录,文件(js.jsp.php.asp)

分享到:

发表评论

89 + 9 =
路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交