redirect in cakephp ssl site routes to http not https

前端 未结 3 555
故里飘歌
故里飘歌 2021-01-15 21:05

I have developed a cakephp site that should use ssl for all pages. It works as expected except when I use redirect in a controller it redirects to http: //subdomain.domain.c

3条回答
  •  走了就别回头了
    2021-01-15 21:54

    Its example is already mentioned in the CookBook http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#usage

    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);
        }
    }
    

提交回复
热议问题