CakePHP 3:重定向到https和非www
这是我的cakephp3htaccess文件CakePHP 3:重定向到https和非www,php,.htaccess,cakephp,redirect,Php,.htaccess,Cakephp,Redirect,这是我的cakephp3htaccess文件 <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}
<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>
重新启动发动机
重写条件%{HTTP_HOST}^www\.(.*)$[NC]
重写规则^(.*)$https://%1/$1[R=301,L]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]
我添加了第一个条件,可以进行下一个重定向
- 从到
- 从到
- 从到
有什么想法吗?谢谢 将第一条规则更改为:
<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>
重新启动发动机
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州,或]
重写条件%{HTTPS}关闭
重写cond%{HTTP_HOST}^(?:www\)?(.+)$[NC]
重写规则(.*)https://%1/$1[R=301,L,NE]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]
在测试此规则之前,请确保清除浏览器缓存。将第一条规则更改为:
<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>
重新启动发动机
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州,或]
重写条件%{HTTPS}关闭
重写cond%{HTTP_HOST}^(?:www\)?(.+)$[NC]
重写规则(.*)https://%1/$1[R=301,L,NE]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]
测试此规则之前,请确保清除浏览器缓存。我认为cakephp目录存在问题,因为此规则重定向到:from domain.com to ok try
RewriteRule
line asRewriteRule(.*)https://%1/$1[R=301,L,NE]
清除浏览器缓存后。Chrome表示ERR_TOO_MANY_redirects无效,直到有另一条规则/代码重定向回http
或添加www
这不是重定向循环。我已经在我的Apache上测试了这个规则,它工作正常。我认为cakephp目录存在问题,因为这个规则重定向到:from domain.com to ok tryRewriteRule
line asRewriteRule(.*)https://%1/$1[R=301,L,NE]
清除浏览器缓存后。Chrome表示ERR_TOO_MANY_redirects无效,直到有另一条规则/代码重定向回http
或添加www
这不是重定向循环。我已经在我的Apache上测试了这个规则,它运行得很好。