轉載:[url]http://msxdnet.blog.51cto.com/165945/75950[/url]
有時候買一個虛拟空間,足可以放N個站點,一般隻要把各站點的對應域名都綁在這個虛拟空間的IP上,然後使用以下代碼便可實作空間共享,站點獨立的效果。
我們以ASP為例:
<%if Request.ServerVariables("SERVER_NAME")="[url]www.weba.com[/url]" then
response.redirect "weba/index.asp"
elseif Request.ServerVariables("SERVER_NAME")="[url]www.webb.com[/url]" then
response.redirect "webb/index.asp"
else
response.redirect "index.asp"
end if%>
這裡有三個域名都綁在同一虛拟空間的IP
[url]www.weba.com[/url]
[url]www.webb.com[/url]
[url]www.webc.com[/url]
将以上代碼另存為 default.asp 放在站點根目下下(假定站點預設頭文檔為default.asp)
如果使用者通路 [url]www.weba.com[/url] 程式跳轉至 空間目錄下weba/index.asp
如果使用者通路 [url]www.webb.com[/url] 程式跳轉至 空間目錄下webb/index.asp
如果使用者通路 [url]www.webc.com[/url] 程式跳轉至 空間目錄下 index.asp
(在某空間提供商站點看到的資料)