我将该网站用于https,我有2个问题,该网站已重定向但是它是301重定向?我没有在.htaccess文件中写任何内容,为什么网站在https中被重定向? 我害怕重复的内容。
我遇到的问题是电子邮件不再起作用了...... 这是代码:
public function initialize()
{
parent::initialize();
$this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']);
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
],
'finder' => 'auth'
]
],
'loginAction' => ['controller' => 'Users', 'action' => 'login', 'prefix' => 'manager'],
'loginRedirect' => ['controller' => 'Pages', 'action' => 'index', 'prefix' => 'manager'],
'logoutRedirect' => ['controller' => 'Users', 'action' => 'login', 'prefix' => 'manager'],
// 'authorize' => 'Controller'
]);
}
public function forceSSL()
{
return $this->redirect('https://' . env('SERVER_NAME') . $this->request->here);
}
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->Security->requireSecure();
$this->checkManager();
$this->set('settings', Configure::read('Settings'));
}
谢谢
答案 0 :(得分:0)
这是解决方案:
public function initialize()
{
parent::initialize();
$this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']);
}
public function forceSSL()
{
return $this->redirect('https://' . env('SERVER_NAME') . $this->request->here);
}
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->Security->requireSecure();
$this->Security->config('unlockedActions', ['contact']);
}
AND:
在Controller.php中更改statut
公共职能重定向($ url,$ status = 302)
成为:
公共功能重定向($ url,$ status = 301)