我的网站对 SEO 有一些严格的要求。
最主要的是将所有 http 请求重定向到 https,这是我通过将其添加到 AppController 中完成的:
public function forceSSL() {
return $this->redirect('https://' . env('SERVER_NAME') . $this->here);
}
public function beforeFilter() {
$this->Security->blackHoleCallback = 'forceSSL';
$this->Security->requireSecure();
}
我遇到的问题是 404 页面,它们不会重定向到 https(例如 www.hublink.net/asdfg)
我也将这两行添加到 .htaccess 文件(来自另一篇文章),并删除了上面的代码,但随后出现“重定向循环”错误
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
最佳答案
RewriteEngine On
# This will enable the Rewrite capabilities
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
关于cakephp 和 https 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25275865/