2014-09-24 153 views
0

一個網站是通過www.mydomain.com/blog/index.html編輯的.htaccess重定向從文件夾中的HTML文件

訪問,但我想它足以輸入www.mydomain.com/blog

我知道.htaccess,我該如何編輯它來重定向請求?

我試了一下,到目前爲止(沒有成功)是這樣的:

RewriteCond %{HTTP_HOST} ^www\.mydomain\.com/blog$ [NC] 
RewriteRule ^$ blog/index.html [L] 

回答

0

您必須目錄結尾的斜線,否則它會導致信息泄露的問題,即人們可以看到一個文件夾的內容,無論那裏有一個index.html文件。如果你不擔心結尾的斜線,那麼所有你需要的是:

DirectoryIndex index.html 
RewriteCond %{THE_REQUEST} \ /+(.*)index\.html 
RewriteRule^/%1 [L,R] 

但是如果你必須刪除斜線和打開你的網站可能目錄列表,那麼你可以嘗試像:

DirectoryIndex index.html 
DirectorySlash Off 

RewriteCond %{THE_REQUEST} \ /+(.*?)/?index\.html 
RewriteRule^/%1 [L,R] 

RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^(.*[^/])$ /$1/ [L]