繁体   English   中英

Cakephp 1.2.5重定向在控制器中不起作用

[英]Cakephp 1.2.5 redirect not working in controller

我在cakephp 1.2.5中有一个应用程序,我尝试使用

$this->redirect(array('controller'=>'controller','action'=>'action'));

重定向之前,我的网站网址是https://example.com/controller/action,但重定向到非SSL(如http://example.com/controller1/action)后,如何重定向到SSL

如果有人有任何想法,请帮助我。

通常在控制器的beforeFilter()中使用安全组件。 您将指定所需的安全限制,安全组件将在启动时强制执行这些限制:

class AppController extends Controller {
    // Add security component
    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);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM