cakephp 和 https 重定向

标签 cakephp ssl https cakephp-2.0 litespeed

我的网站对 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

参见 https://wiki.apache.org/httpd/RewriteHTTPToHTTPS 它对我有用。

关于cakephp 和 https 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25275865/

相关文章:

php - Security::hash() 不返回相同的哈希值

.htaccess - 显示 https 状态的域 "Masking"

amazon-web-services - ACM 请求的公共(public) SSL 证书未出现在 CloudFront 中

python - 使用 httplib2 打开 ssl 连接时出错

php - 使用 CakePHP 发送警报的方法

cakephp 并创建一个移动网站

ssl - 没有数字证书的 Google Search Appliance 可以扫描启用了 SSL 的站点吗?

ssl - 如何在 Postman 中使用自签名证书?

CakePHP、URL 和 SEO

使用 Internet Explorer 在 sauce labs 上出现 SSL 握手错误