2013-07-18 205 views
0

我有以下.htaccess文件:循環重定向

AddDefaultCharset utf-8 
RewriteEngine on 
Options +SymLinksIfOwnerMatch 
RewriteBase/

# redirect all www-requests to no-www 
# - 
RewriteCond %{HTTP_HOST} ^www\.site\.com$ [NC] 
RewriteRule ^(.*)$ http://site.com/$1 [R=301,L] 

# redirect all home pages to/(root) 
# - 
RewriteCond %{THE_REQUEST} ^.*/index\.(php|html?) 
RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,L] 

# remove trailing slash from dirs 
# - 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)/$ /$1 [R=301,L] 

# automatically add index.php when needed 
# - 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|login\.php|reg\.php|robots\.txt|css/|js/) 
RewriteRule ^(.*)$ /index.php [L] 

.htaccess文件應做到以下幾點(搜索引擎優化):

  1. 轉換到無WWW(http://www.site.com應成爲http://site.com
  2. 尾隨斜線應該轉換爲無拖尾斜槓的URI:http://site.com/me/應該被重定向​​
  3. 點與index.php/index.html所有的URI應該轉換爲根本不值一提:http://site.com/admin/index.phphttp://site.com/admin/應該不過的結果的.htaccess在循環重定向當前版本試圖訪問(http://site.com/admin)時,最終顯示爲http://site.com

。瀏覽器應該讀取的真實文件是http://site.com/admin/index.php

任何人都可以請幫我解決這個問題嗎?

回答

1

有一個名爲mod_dir的模塊會自動加載,並且會導致缺少尾部斜槓的目錄的請求被重定向到尾部斜線。您可以使用DirectorySlash指令將其關閉,但在關閉時請注意安全警告。如果您將其關閉並且默認索引不會加載,則會出現信息泄露安全問題。然而,你的lats規則(看起來像)它這樣做,儘管不正確。

首先,關閉DirectorySlash

DirectorySlash Off 

然後,你需要的最後一個規則更改爲:

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