2013-09-26 61 views
2

我的.htaccess文件正在創建一個重定向循環。我在網上搜索並嘗試了很多品種,包括很多來自這個網站,但仍然無法實現它的工作。它的目的是從URL的末尾刪除.html。.htaccess刪除.html導致重定向循環

這裏是我的代碼:

RewriteEngine On 

RewriteCond %{SCRIPT_FILENAME}/ -d 
RewriteCond %{SCRIPT_FILENAME}.html !-f 
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L] 

RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteRule ^(.+)\.html$ /$1 [R=301,L] 

RewriteCond %{SCRIPT_FILENAME}.html -f 
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L] 

回答

1

替換所有的代碼與此:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

## hide .html extension 

# To externally redirect /dir/foo.html to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.+?)\.html?[/?\s] [NC] 
RewriteRule^%1? [NE,R=301,L] 

# To internally forward /dir/foo to /dir/foo.html 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.html -f 
RewriteRule ^(.+?)/?$ /$1.html [L] 

## append trailing slash if needed 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L] 
+0

它現在給我一個內部服務器錯誤。 – Jolly

+0

檢查你的error.log並告訴我什麼是錯誤。 – anubhava

+0

如何檢查? – Jolly