2011-11-14 60 views
32

我的網站上有文檔根目錄〜/的public_html但我想所有的文件添加到〜/的public_html/WWW使用htaccess的更改文檔根目錄

有沒有辦法與htaccess的做到這一點?

謝謝。

+1

這是常見的疑惑。一些用戶總是熱衷於關閉問題。他們會從中得到什麼? –

+0

在這裏問了一個類似的問題,幸好還沒有關閉:http://stackoverflow.com/questions/16512881/how-to-set-document-root-to-bea-a-subdirectory-using-htaccess-and -not-vhost –

回答

51

以下行添加到.htaccess文件中的public_html文件夾:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR] 
RewriteCond %{HTTP_HOST} ^www.domain-name.com$ 
RewriteCond %{REQUEST_URI} !folder/ 
RewriteRule (.*) /folder/$1 [L] 
+1

您能解釋一下'RewriteCond%{HTTP_HOST}^domain-name.com $ [NC,OR]'和'RewriteCond%{HTTP_HOST}^www.domain-name.com $'的用途嗎? ?我正在使用它,沒有這兩行,它似乎正在工作... –

+0

這使得條件模式不區分大小寫,'A-Z'和'a-z'之間沒有區別。 – Vilva

+5

是不是可以在httpd.conf文件中設置htaccess文件中的文檔根目錄,例如'DocumentRoot「c:/ inetpub/wwwroot」'? –