# Redirecting Phoenix app from HTTP -\> HTTPS and www -\> apex not working?

**URL:** <https://community.fly.io/t/redirecting-phoenix-app-from-http-https-and-www-apex-not-working/3697>\
**Category:** Phoenix\
**Tags:** elixir\
**Created:** [January 17, 2022, 7:57pm UTC](https://community.fly.io/t/redirecting-phoenix-app-from-http-https-and-www-apex-not-working/3697 "2022-01-17T19:57:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nezteb](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/nezteb/32/17062_2.png) [@Nezteb](https://community.fly.io/u/Nezteb)\
**Post date:** [January 17, 2022, 7:57pm UTC](https://community.fly.io/t/redirecting-phoenix-app-from-http-https-and-www-apex-not-working/3697/1 "2022-01-17T19:57:53Z")

</div>

I’m trying to make it so that my `fly.io` app redirects:

- HTTP → HTTPS
- www → apex

My app SSL config: (`fly.io` doesn’t give you file access to your key/cert, so I’m not sure what to put in those, if I get rid of them things seem to work fine?)

 ![Screen Shot 2022-01-17 at 1.54.54 PM](https://global.discourse-cdn.com/fly1/original/3X/7/3/73daf175cbf7850998f545db47010e5a52070499.png)  
 ![Screen Shot 2022-01-17 at 1.55.07 PM](https://global.discourse-cdn.com/fly1/original/3X/e/8/e867b71d740ad951fb31946a6192360af5a5f034.png)

My SSL cert is all good:

 ![Screen Shot 2022-01-17 at 1.48.28 PM](https://global.discourse-cdn.com/fly1/original/3X/6/f/6ff0ffc806b76a2d9ec963515259715485be6c16.png)

My secrets:

 ![Screen Shot 2022-01-17 at 1.51.31 PM](https://global.discourse-cdn.com/fly1/original/3X/0/3/03a7d7f026dea5871dd3163285c21fb1c62712eb.png)

My `fly.toml`:

 ![Screen Shot 2022-01-17 at 1.52.06 PM](https://global.discourse-cdn.com/fly1/original/3X/7/e/7eeca60b9955f6a83173de8669587e1ec539bcbb.png)

As for the redirection of www to the apex domain, I wrote this myself and it didn’t work. I then tried using [GitHub - remi/plug\_canonical\_host: PlugCanonicalHost ensures that all requests are served by a single canonical host.](https://github.com/remi/plug_canonical_host), but that doesn’t work either. I’m not sure if I’m doing something wrong or if `fly.io` is doing some automagical stuff in the background I’m not seeing.

Any ideas?

---

<div class="post-metadata">

**Author:** ![chrismccord](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/chrismccord/32/50976_2.png) [@chrismccord](https://community.fly.io/u/chrismccord)\
**Post date:** [January 17, 2022, 8:20pm UTC](https://community.fly.io/t/redirecting-phoenix-app-from-http-https-and-www-apex-not-working/3697/2 "2022-01-17T20:20:10Z")

</div>

Fly terminates SSL at the proxy, so you should only need to configure:

```auto
force_ssl: [rewrite_on: [:x_forwarded_proto]]

```

For the canonical host, if you can share what you wrote, I could comment further, but a simple plug should do the job just fine 🙂

---

<div class="post-metadata">

**Author:** ![Nezteb](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/nezteb/32/17062_2.png) [@Nezteb](https://community.fly.io/u/Nezteb)\
**Post date:** [January 17, 2022, 8:52pm UTC](https://community.fly.io/t/redirecting-phoenix-app-from-http-https-and-www-apex-not-working/3697/3 "2022-01-17T20:52:55Z")

</div>

Ah, so the Fly proxy handles all SSL? So should I get rid of all of the Phoenix-specific SSL/HTTPS config?

Once I do that, the HTTP → HTTPS part works, though the www redirect does not.

In `config/prod.exs`: (I made sure to use `flyctl secrets set CANONICAL_HOST=nezteb.net`)

 ![Screen Shot 2022-01-17 at 2.43.35 PM](https://global.discourse-cdn.com/fly1/original/3X/8/b/8bfc1048485e631bc6d3a752559dc129b9ab9a6e.png)

in `lib/nezteb_web/endpoint.ex`:

 ![Screen Shot 2022-01-17 at 2.43.42 PM](https://global.discourse-cdn.com/fly1/original/3X/5/1/51d3f734e516c08ab462331508a8a7be9ddcc6e4.png)

UGH literally as I uploaded that last screenshot, I realize that I didn’t change the app name in the function:

```auto
:my_app # should have been :nezteb...
    |> Application.get_env(:canonical_host)

```

Now things seem to be working. Thanks Chris! ❤
