2017-06-06 54 views
0

什麼能阻止Apache重定向。導致這些重定向的原因是什麼?什麼可以阻止Apache重定向。導致這些重定向的原因是什麼?

的.htaccess

RewriteEngine On 
RewriteBase/
Options -MultiViews 
DirectoryIndex /public/index.php 

RewriteCond %{HTTPS} off 
RewriteRule ^https://somedomain.com%{REQUEST_URI} [NE] 

RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteCond %{ENV:REQUEST_FILENAME} !-d 
RewriteCond %{ENV:REQUEST_FILENAME} !-f 
RewriteCond %{ENV:REQUEST_FILENAME} !-l 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/public/index\.php?url=$1 [QSA,R=301,L] 

使用somedomain.com/login 我越來越ERR_TOO_MANY_REDIRECTS

https://somedomain.com/public/index.php?url=public/index.php&url=public/index.php < ...>

我相信L時,應停止重定向?纔不是?

+0

你使用像symfony這樣的路由框架嗎? – German

回答

1

我相信L應該停止重定向?纔不是?

L不停止重定向。 L flag(Last)剛剛停止當前的mod_rewrite循環,並導致mod_rewrite規則再次從開始循環,因此它在while循環中的工作方式與continue相似。

您必須從最後一個路由規則中刪除http://R=301標誌以避免外部重定向。

Options -MultiViews 
DirectoryIndex index.php 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTPS} off 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

RewriteCond %{ENV:REQUEST_FILENAME} !-d 
RewriteCond %{ENV:REQUEST_FILENAME} !-f 
RewriteRule ^t/(.*)$ public/index.php?url=$1 [QSA,L,NC] 

請確保在測試此更改之前清空瀏覽器緩存。

+0

謝謝!但現在我得到很長的重定向。 – olga

+0

它可以工作,但要到達頁面somedomain.com/login需要一分鐘 – olga

+0

這不能歸結於規則。規則只需要幾毫秒的時間來執行。你可以在Chrome開發工具中測試看看時間統計。 – anubhava

相關問題