我有一个托管在由 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);
}
使用此代码,即使任何链接点击都不起作用。