redirect in cakephp ssl site routes to http not https

前端 未结 3 557
故里飘歌
故里飘歌 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:48

    I found the error it was a misconfiguration of Apache.

    Trying out Jamies solution, the site ended up in a redirect loop, because RequestHandler->isSSL() returned false even if the request was https. I then discovered that the $_SERVER['https'] was not set and the $_SERVER['port'] was 80, not 443 as expected.

    At that point I have placed my ssl directives in sites-available/default,

    SSLEngine on
    SSLCertificateFile [path to cert file]
    SSLCertificateKeyFile [path to keyfile]
    

    Moving the ssl directives to the virtual host for the subdomain resolved the issue, with redirect loops.

    Actually is also solved my initial problem because the method Router::url checks for $_SERVER['https'] if set it generates a url that starts with https: otherwise just http:

    I have tested both Jameies solution and my own with rewrite rules in .htaccess and they both work as expected after the fix.

    Tim

提交回复
热议问题