cakephp2强制Windows服务器上的https重定向

问题描述 投票:0回答:1

我有一个由Cakephp2.7开发的Windows服务器上托管的子域在服务器上安装了SSL,如果显式键入https,但不会自动将http转换为https,则可以正常工作我想自动将任何网址转换为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
1个回答
0
投票
这是其他问题,如果卡在同一问题中通过在“ AppController”类的beforeFilter()方法中添加以下代码,我解决了强制重定向到https的问题

//https redirect if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === "off") { $location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $location); exit; }

© www.soinside.com 2019 - 2024. All rights reserved.