Application HTTPS but CakePHP redirect controller/action to HTTP

Hello,

I have a problem with my site CakePHP 4.1

in production, my server is only HTTPS and server port 80 is close.

Access to CakePHP is correct to production, i obtains my login page.

but Cakephp redirect HTTP then click button login.
this button use controller, to call $this->redirect([controller->user, action->index])

why CakePHP not redirect to HTTPS this same current page but redirect to HTTP ?

thank you for help me,
Mickael

Be sure to check your config (app_local.php and app.php in the config folder). It looks like the fullBaseUrl attribute can be set to override the HTTP_HOST env variable that looks to be causing you trouble.

If that doesn’t work, you should be able to do this via your webserver. Here is a tutorial for NGINX and Apache.

Another, and probably the easiest option, is to just use CloudFlare. They offer an “HTTPS Rewrites” setting/option that will automagically rewrite all requests to HTTPS.

1 Like

Configure your root folder .htaccess file (application_name/.htaccess)

> <IfModule mod_rewrite.c>
>     RewriteEngine on
>     RewriteCond %{HTTPS} !=on
>     RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
>     RewriteRule    ^(\.well-known/.*)$ $1 [L]
>     RewriteRule    ^$    webroot/    [L]
>     RewriteRule    (.*) webroot/$1    [L]
> </IfModule>

this always redirect to https