網(wǎng)站建設(shè)將多個文件夾源碼怎么整合在一起?
時間:2023-11-10 23:54:01 | 來源:網(wǎng)站運營
時間:2023-11-10 23:54:01 來源:網(wǎng)站運營
網(wǎng)站建設(shè)將多個文件夾源碼怎么整合在一起?:這不就是
一個網(wǎng)站虛擬主機空間放多個網(wǎng)站(源碼)嘛?
一個虛擬主機或空間實現(xiàn)放多個網(wǎng)站的方法,文章比較長,核心代碼在尾部。有的朋友為了省錢或者為了更好的管理網(wǎng)站,想在一個虛擬主機或者空間中放多個網(wǎng)站,但是不知道該怎么操作?這里就講一下我是怎么操作的
準(zhǔn)備工具:
- 買一個虛擬主機或者空間,可以去http://www.jwzjs.com/services/webhosting/twhost.asp看看,所有港臺主機都可以綁定多個域名。
- 解析2個域名(二級域名也可以的)
注意事項:
下面我說的是針對幾種空間,你們需要看好你們的是什么空間然后用什么代碼!
虛擬主機本身支持綁定子目錄這里不討論
方法一:利用js代碼實現(xiàn)一個空間安裝多個網(wǎng)站的代碼
1.在把域名綁定在空間上(
http://www.aaa.com和
http://www.bbb.com)
2.把
http://www.aaa.com網(wǎng)站文件上傳到根目錄,把
http://www.bbb.com的網(wǎng)站文件放到../bbb目錄里(z這里最好用../不要用/防止訪問出現(xiàn)錯誤,以及方便網(wǎng)站分離)
3.然后把下面代碼保存為domain.js(不同域名產(chǎn)生跨域的問題,直接獲取當(dāng)前域名)然后上傳到根目錄就行了
代碼:
switch(location.host){
case ‘www.bbb.com:
location.href=
http://www.bbb.ccom/bbb/break;
}
4.然后向空間根目錄的首頁的<head> </head>直接用script引入domain.js代碼:(這里我是直接放在空間里的js文件夾里)
<script src=”js/domain.js”type=”text/javascript”>
</script>
5.完成這些后你可以測試一下你先訪問
http://www.aaa.com看看是不是正常的,然后在訪問
http://www.bbb.com看看如果沒有問題就成功了
如果你想添加更多的話你只需要在domain,js文件里寫好就行了
方法二:(asp空間,鑒于聚網(wǎng)志成主機的空間均同時支持asp和php,所有都可以用。)
我是利用這個server.Transfer(””)來實現(xiàn)一個空間多個網(wǎng)站的方法
1.你還是先綁定域名
2.把下面的代碼加人你虛擬主機的首頁asp文件里就行了
3.<%sn=lcase(Request.ServerVariables(“SERVER_NAME”)) ‘用于獲取用戶是通過哪個域名訪問的,并轉(zhuǎn)換成小寫
if sn=’
http://www.aaa.com or sn=”aaacom” then server.Transfer(“default1.asp”)
if sn=’
http://www.bbb.com’ or sn=”bbb.com” then server.Transfer(“index.html”)%
解釋:
如果訪問者輸入的域名是
http://www.aaa.com或者
http://aaa.com的話那么就訪問default1.asp
如果是用
http://www.bbb.com或者
http://bbb.com的話就調(diào)用index.html
關(guān)于server中transfer和response中的redirect的區(qū)別
這里我只能說:
1.transfer簡單適合初學(xué)者
2.transfer減少了對服務(wù)器的請求
3.關(guān)于一些頁面參數(shù)的問題等
4.Transfer不會阻止搜索引擎對你的網(wǎng)站一些收錄
redirect對使用者有一定的技術(shù)要求
方法三:(方便管理)
利用asp文件自動識別訪問者輸入域名,來分別訪問網(wǎng)站文件
缺點是(比如訪問者是訪問
http://bbb.com域名會看見是
http://bbb.com/bbb 因為網(wǎng)站文件在bbb文件里)
方法實現(xiàn):
先建立一個index.asp文件
然后把
http://www.aaa.com網(wǎng)站的文件放放在aaa文件里
把
http://www.bbb.com網(wǎng)站的文件放在bbb文件里
以次類推。。。。。。。
index.asp的代碼下:
<%if Request.ServerVariables(“SERVER_NAME”)=”
http://www.aaa.com ” then
response.redirect “aaa/index.asp”
elseif Request.ServerVariables(“SERVER_NAME”)=”
http://www.bbb.com ” then
response.redirect “bbb/index.asp”
else
response.redirect “aaa/index.asp”
end if%>
如果用戶訪問
http://www.aaa.com就跳轉(zhuǎn)到空間目錄下aaa/index.asp
如果用戶訪問
http://www.bbb.com就跳轉(zhuǎn)到空間目錄下bbb/index.asp
如果用戶訪問沒有指定訪問就跳轉(zhuǎn)到空間目錄下aaa/index.asp
這樣無限。。。。。
關(guān)于asp空間部署多個網(wǎng)站的代碼:
第一個
程序代碼
<%
if Request.ServerVariables(“SERVER_NAME”)=”www.aaa.com” then
response.redirect “index.htm”
else
response.redirect “index2.htm”
end if
%>
第二個
程序代碼
<%
select case request.servervariables(“http_host”)
case “www.aaa.com”
Server.Transfer(“index.htm”)
case “www.bbb.com”
Server.Transfer(“index2.htm”)
case “www.aaa.com”
Server.Transfer(“index3.htm”)
…… 繼續(xù)添加 ……
end select
%>
第三個
程序代碼
<%
if instr(Request.ServerVariables(“SERVER_NAME”),”0/’>www.aaa.com”)>0 then
response.redirect “index.htm”
elseif instr(Request.ServerVariables(“SERVER_NAME”),”0/’>www.bbb.com”)>0 then
response.redirect “index2.htm”
elseif instr(Request.ServerVariables(“SERVER_NAME”),”0/’>www.aaa.com”)>0 then
response.redirect “index3.htm”
end if
%>
第四個
程序代碼
<%
if Request.ServerVariables(“SERVER_NAME”)=”www.aaa.com” then
response.redirect “index.htm”
elseif Request.ServerVariables(“SERVER_NAME”)=”www.bbb.com” then
response.redirect “index2.htm”
elseif Request.ServerVariables(“SERVER_NAME”)=”www.aaa.com” then
response.redirect “index3.htm”
end if
%>
第五個
程序代碼
<%
if Request.ServerVariables(“SERVER_NAME”)=”www.aaa.com” then
Server.Transfer(“index.htm”)
elseif Request.ServerVariables(“SERVER_NAME”)=”www.bbb.com” then
Server.Transfer(“index2.htm”)
elseif Request.ServerVariables(“SERVER_NAME”)=”www.aaa.com” then
Server.Transfer(“index3.htm”)
else
Server.Transfer(“other.htm”)
end if
%>
關(guān)于PHP空間放多個網(wǎng)站的代碼
第一個:
程序代碼
if($HTTP_HOST==”www.aaa.com”){
Header(“Location: index.htm”);
}
elseif($HTTP_HOST==”www.bbb.com”){
Header(“Location: index2.htm”);
}
else{
Header(“Location: other.htm”);
}
第二個:
程序代碼
if($HTTP_HOST==”www.aaa.com”){
require “index.htm”;
}
elseif($HTTP_HOST==”www.bbb.com”){
require “index2.htm”;
}
else{
require “other.htm”;
}
如果你的空間是純靜態(tài)的話那么就用上面(代碼)
把下面代碼保存為domain.js文件
switch(location.host){
case ’
http://www.aaa.com’:
location.href=”
http://www.aaa.com/index.htm”
case ’
http://www.bbb.com’:
location.href=”
http://www.bbb.com/index2.htm”
break;
}
然后在空間根目錄的首頁<head></head>之間添加
<script src=”js/domain.js”type=”text/javascript”>
</script>
然后在輸出
http://www.aaa.com訪問看看是不是
http://www.aaa.com在測試
http://www.bbb.com看看
PHP首頁代碼判斷域名跳轉(zhuǎn)到指定的頁面或地址本代碼主要一個虛擬空間里建立多個網(wǎng)站,每個網(wǎng)站放到不同的子目錄里,然后在根目錄下根據(jù)不同的域名訪問跳轉(zhuǎn)到不同的目錄,從而打開不同的網(wǎng)站。實現(xiàn)一個空間放多個網(wǎng)站的效果。
<?php
switch ($_SERVER["HTTP_HOST"])
{
case "
http://www.nuobg.com":
header("location:blog/index.php");
break;
case "
http://www.abcwj.com":
header("location:do/index.php");
break;
case "
http://www.gow6.com":
header("location:b2b/index.php");
break;
}
?>
如果用戶訪問
http://www.vps12.com 程序跳轉(zhuǎn)至 空間目錄下 blog/index.php
如果用戶訪問
http://www.dnsff.com 程序跳轉(zhuǎn)至 空間目錄下 do/index.php
如果用戶訪問
http://www.dns173.com 程序跳轉(zhuǎn)至 空間目錄下 b2b/index.php
如果虛擬主機不支持子目錄綁定有效的辦法就是這樣了!希望對大家有幫助。
以上就是博主測試研究的一些關(guān)于一個虛擬主機或空間實現(xiàn)放多個網(wǎng)站的方法!
如果對大家有用請大家分享給你的朋友!分享是美德!
當(dāng)然,此技術(shù)不適合做SEO優(yōu)化使用,畢竟首頁有跳轉(zhuǎn)對于網(wǎng)站優(yōu)化來說略微有些影響,所以在僅僅做演示或者展示網(wǎng)站則可以使用,例如演示網(wǎng)站源碼、網(wǎng)站模板的時候可以這么操作。