2015-09-18 54 views
0

我知道還有很多類似於這個問題的其他問題,我嘗試followinf其中的一些,但沒有運氣。使用.htaccess從網址中刪除文件夾

我有一個名爲test.com的網站,我需要當有人爲test.com顯示內容而在test.com中顯示內容時沒有在家裏。此刻

我htaccess文件是這樣的:

RewriteEngine on 
RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule /(.*) home/$1 [L] 
    RewriteRule /home/(.*) /$1 [L,R=302] 

RewriteOptions inherit 

RewriteCond %{HTTP_HOST} ^test\.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.test\.com$ 

但是當我鍵入test.com它顯示文件夾列表,裏面沒有回家的內容。

我在做什麼錯了?

感謝

+0

此htaccess位於何處? – anubhava

+0

我使用的是cPanel,它位於public_html文件夾中 – Nick

回答

1

您可以簡化您的規則,這個根的.htaccess

RewriteEngine on 
RewriteBase/

RewriteRule ^$ home/ [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^((?!home/).+)$ home/$1 [L,NC] 

確保測試此之前,清除瀏覽器緩存。

+1

真棒!完美地工作。非常感謝 – Nick