【发布时间】:2020-04-25 22:06:24
【问题描述】:
我有一个托管在由 cakephp2.7 开发的 windows 服务器上的子域 在服务器上安装 SSL,如果显式键入 https 但不会自动将 http 转换为 https,则它可以工作 我想自动将任何 url 转换为 https
用 .htaccess 文件尝试了很多东西,但没有任何效果 当前htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
也试过
public $components = array('Security');
public function beforeFilter() {
$this->Security->blackHoleCallback = 'forceSSL';
$this->Security->requireSecure();
}
// Add this function in your AppController
public function forceSSL() {
return $this->redirect('https://' . env('SERVER_NAME') . $this->here);
}
使用此代码,即使任何链接点击都不起作用。
【问题讨论】:
标签: .htaccess https windows-server-2012 cakephp-2.7