CakePHP 3:重定向到https和非www
问题描述:
这是我的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>
我添加的第一个条件,可能使下一个重定向
但我不能重定向
任何想法?谢谢!!
答
改变你的第一条规则:
<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>
确保测试这个规则之前清除浏览器缓存。
我认为有cakephp目录的问题,因为这条规则重定向到:从domain.com到https://domain.com/app/webroot/ – mauriblint
确定尝试'RewriteRule'行为'RewriteRule(。*)https ://%1/$ 1 [R = 301,L,NE]'清除浏览器缓存后。 – anubhava
Chrome说ERR_TOO_MANY_REDIRECTS – mauriblint