# Application HTTPS but CakePHP redirect controller/action to HTTP

**URL:** https://discourse.cakephp.org/t/application-https-but-cakephp-redirect-controller-action-to-http/8284
**Category:** Need Help
**Created:** [August 25, 2020, 5:56pm UTC](https://discourse.cakephp.org/t/application-https-but-cakephp-redirect-controller-action-to-http/8284 "2020-08-25T17:56:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mhulin](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@mhulin](https://discourse.cakephp.org/u/mhulin)
#### Post date: [August 25, 2020, 5:56pm UTC](https://discourse.cakephp.org/t/application-https-but-cakephp-redirect-controller-action-to-http/8284/1 "2020-08-25T17:56:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![anon81960487](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@anon81960487](https://discourse.cakephp.org/u/anon81960487)
#### Post date: [August 26, 2020, 4:15am UTC](https://discourse.cakephp.org/t/application-https-but-cakephp-redirect-controller-action-to-http/8284/2 "2020-08-26T04:15:08Z")

</div>

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](https://www.hostinger.com/tutorials/nginx-redirect/) and [Apache](https://www.namecheap.com/support/knowledgebase/article.aspx/9821/38/apache-redirect-to-https).

Another, and probably the easiest option, is to just use [CloudFlare](https://cloudflare.com). They offer an “HTTPS Rewrites” setting/option that will automagically rewrite all requests to HTTPS.

---

<div class="post-metadata">

### Author: ![debendra986](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@debendra986](https://discourse.cakephp.org/u/debendra986)
#### Post date: [August 29, 2020, 5:43am UTC](https://discourse.cakephp.org/t/application-https-but-cakephp-redirect-controller-action-to-http/8284/3 "2020-08-29T05:43:51Z")

</div>

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
