2015-10-20 149 views
1

這是我的CakePhp 3 htaccess文件。CakePHP 3:重定向到https和非www

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L] 



    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L]  
</IfModule> 

我添加的第一個條件,可能使下一個重定向

但我不能重定向

任何想法?謝謝!!

回答

0

改變你的第一條規則:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{HTTP_HOST} ^www\. [NC,OR] 
    RewriteCond %{HTTPS} off 
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] 
    RewriteRule (.*) https://%1/$1 [R=301,L,NE] 

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule^index.php [L]  
</IfModule> 

確保測試這個規則之前清除瀏覽器緩存。

+0

我認爲有cakephp目錄的問題,因爲這條規則重定向到:從domain.com到https://domain.com/app/webroot/ – mauriblint

+0

確定嘗試'RewriteRule'行爲'RewriteRule(。*)https ://%1/$ 1 [R = 301,L,NE]'清除瀏覽器緩存後。 – anubhava

+0

Chrome說ERR_TOO_MANY_REDIRECTS – mauriblint

相關問題