2014-07-02 131 views
1

我是一個初學者,當涉及到使用htaccess的東西,所以請耐心等待我的愚蠢問題。我知道這已被解決了很多(例如,hereherehere),但它似乎不適用於我的情況。我的瀏覽器顯示與此代碼「重定向循環」的錯誤在我的htaccess文件:htaccess重定向所有流量到https

<IfModule mod_rewrite.c> 
    <IfModule mod_negotiation.c> 
     Options -MultiViews 
    </IfModule> 

    RewriteEngine On 

    # Redirect Trailing Slashes... 
    RewriteRule ^(.*)/$ /$1 [L,R=301] 

    # Handle Front Controller... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L] 

    # Trying to redirect to https 
    RewriteCond %{HTTPS} off 
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
</IfModule> 

我知道這可能有事情做與RewriteCond之前,我重定向到https的RewriteRule,但我不真的知道我在這裏做什麼,我不知道要改變什麼。

更新:

一些更多的信息可能會有所幫助:

  1. 當我刪除了「重定向到https」開頭的代碼和手動鍵入https://my.site.com它加載就好了。
  2. 此外,在我意外刪除我的目錄中的.htaccess文件之前,重定向到https的工作效果很好。
  3. 我嘗試重定向的應用程序駐留在另一個也具有.htaccess文件的應用程序的子文件夾中。下面是該應用程序的代碼:

    <IfModule mod_rewrite.c> RewriteEngine On RewriteBase/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteEngine On </IfModule>

這是螢火說: 1st screenshot2nd screenshot

回答

1

你的規則修改訂單,並保持先於其他內部重寫規則301條規定:

<IfModule mod_rewrite.c> 
    <IfModule mod_negotiation.c> 
     Options -MultiViews 
    </IfModule> 

    RewriteEngine On 

    # Redirect Trailing Slashes... 
    RewriteRule ^(.*)/$ /$1 [L,R=301] 

    # Trying to redirect to https 
    RewriteCond %{HTTPS} off 
    RewriteCond %{SERVER_PORT} !=443 
    RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301] 

    # Handle Front Controller... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L] 

</IfModule> 
+0

仍然得到「此網頁有重定向循環」 – sterfry68

+0

在不同的瀏覽器中測試。 – anubhava

+0

剛剛在Firefox中測試過,並且收到類似的消息:「Firefox已經檢測到服務器以永遠不會完成的方式重定向該地址的請求。」 – sterfry68

相關問題