2012-09-18 42 views
1

末看看這個樣本虛擬主機片段:虛擬文件夾名稱自動附加到基礎URL

<VirtualHost *:80> 
    DocumentRoot /web/content 
    ServerName me.example.com 
</VirtualHost> 

/網頁/內容包含2個文件,的index.html頁。 html和子目錄顏色包含yellow.htmlindex.html包含像href="/page.html"href="/colors/yellow.html"這樣的鏈接,使用/來引用web根目錄。

有沒有辦法在內部使用me.example.com/test/根網站的?換句話說,當用戶轉到http://me.example.com/test/時,我想獲取/web/content/index.html。因此,URL中的/test/本質上將是一個虛擬「文件夾」。

基本上,我想me.example.com/test功能完全如何子域(如,test.me.example.com)會。像設置ServerName me.example.com/test(但我知道這是行不通的)。

我知道我可以簡單地做一個真正的文件夾/網頁/內容/測試並把一切都放在那裏,但是這會破壞我的鏈接與/開始,因爲他們仍然會參考/網頁/內容作爲網頁根。添加像Alias /test /web/content這樣的指令時會出現同樣的問題。

我在這裏有什麼選擇嗎?也許使用RewriteBase? (我已經嘗試了幾件事情,沒有運氣。)

回答

2

嘗試把這個在htaccess的文件在您的文檔根目錄

RewriteEngine On 
RewriteCond %{REQUEST_URI} ^/test/(.*)$ 
RewriteCond %{DOCUMENT_ROOT}/%1 -f [OR] 
RewriteCond %{DOCUMENT_ROOT}/%1 -d 
RewriteRule^/%1 [L] 

這將把/test/ URI路徑文檔根目錄。如果你想說,將其映射到顏色文件夾,你會這樣做:

RewriteEngine On 
RewriteCond %{REQUEST_URI} ^/test/(.*)$ 
RewriteCond %{DOCUMENT_ROOT}/colors/%1 -f [OR] 
RewriteCond %{DOCUMENT_ROOT}/colors/%1 -d 
RewriteRule^/colors/%1 [L] 
+0

謝謝,正是我需要的!現在我要早點回家。 :) – sgroves