2011-12-16 70 views
1

我的根目錄包含一些.html文件。 我想刪除地址欄一個.html的擴展,到底這樣添加斜線:http://domain.com/page/ 我試過很多的解決方案,其中之一:刪除擴展名並在靜態html上添加斜線

RewriteEngine on 
RewriteBase/

# redirect from ww to non-www 
RewriteCond %{HTTP_HOST} ^www.nightmaar.com$ [NC] 
RewriteRule ^(.*)$ http://nightmaar.com/$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.html 
RewriteRule (.*)\.html$ /$1/ [L,R=301] 

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

RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule .*[^/]$ $0/ [L,R=301] 

但瀏覽器提供了一個錯誤(太多重定向)。當我試圖訪問我的靜態html頁面時,沒有從page.html重定向到/ page /。

請幫我解決一下這個問題:S

回答

2

你幾乎做到了!

下面是應該工作:

RewriteEngine On 
RewriteBase/

# redirect from www to non-www 
RewriteCond %{HTTP_HOST} ^www.nightmaar.com$ [NC] 
RewriteRule ^(.*)$ http://nightmaar.com/$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.html 
RewriteRule (.*)\.html$ /$1/ [L,R=301] 

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

# Remove trailing slash: 
RewriteRule (.*)/$ $1 [L] 

# Now test without the trailing slash: 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule . %{REQUEST_FILENAME}.html [QSA,L] 
+0

嗯,檢查這種方式 - 不工作。 – 2011-12-16 10:27:16