# Redirect HTTP to HTTPS - which approach is better?

**URL:** <https://community.traefik.io/t/redirect-http-to-https-which-approach-is-better/6720>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [June 30, 2020, 10:57pm UTC](https://community.traefik.io/t/redirect-http-to-https-which-approach-is-better/6720 "2020-06-30T22:57:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/shot/32/2312_2.png) [@shot](https://community.traefik.io/u/shot)\
**Post date:** [June 30, 2020, 10:57pm UTC](https://community.traefik.io/t/redirect-http-to-https-which-approach-is-better/6720/1 "2020-06-30T22:57:49Z")

</div>

The technique described in [this blog post](https://containo.us/blog/traefik-2-0-docker-101-fc2893944b9d/) under the heading " **I want HTTPS redirection!**" is done in the dynamic configuration, whereas there's also the following approach via static/startup configuration:

```auto
"--entryPoints.web.http.redirections.entryPoint.to=websecure"
"--entryPoints.web.http.redirections.entryPoint.scheme=https"

```

Is one approach "better" than the other?

Also, does the **Let's Encrypt** ACME challenge require HTTP, or can it be done over HTTPS? If the former and `http --> https` redirection is in place, how can it succeed? And if the latter, and redirection is in place, how does LE access a secure URL that has no cert in order to generate the initial cert?

---

<div class="post-metadata">

**Author:** ![akhfa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/akhfa/32/2234_2.png) [@akhfa](https://community.traefik.io/u/akhfa)\
**Post date:** [July 1, 2020, 6:46pm UTC](https://community.traefik.io/t/redirect-http-to-https-which-approach-is-better/6720/2 "2020-07-01T18:46:10Z")

</div>

Hi,

Sorry maybe this is not your answer, but from what I tried

```auto
--entryPoints.web.http.redirections.entryPoint.to=websecure

```

The redirection is work, but somehow there will be /tcp/ appended in the url

```auto
curl -I http://some-address.com
HTTP/1.1 308 Permanent Redirect
Location: https://some-address.com:443/tcp/

```

When I use this

```auto
--entryPoints.web.http.redirections.entryPoint.scheme=https

```

the redirection doesn't works on my setup

Do you have same issue, or both of the static configuration are working on your setup?

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [July 1, 2020, 6:51pm UTC](https://community.traefik.io/t/redirect-http-to-https-which-approach-is-better/6720/3 "2020-07-01T18:51:34Z")

</div>

Hi @shot

That blog post was October 2019 the [2.2 release in March](https://containo.us/blog/traefik-2-2-ingress/) introduced the EntryPoint Defaults.

> [@shot](#):
>
> Is one approach "better" than the other?

Better? I think so. If you have no intention of doing http(and why would you these days) then this becomes one of your default parameters.

> [@shot](#):
>
> Also, does the **Let's Encrypt** ACME challenge require HTTP, or can it be done over HTTPS?

You can specify either [httpChallenge](https://docs.traefik.io/https/acme/#httpchallenge) or [tlsChallenge](https://docs.traefik.io/https/acme/#tlschallenge) for the certificate resolver. Don't forget dnsChallenge too.

The httpChallenge documentation states:

> Redirection is fully compatible with the `HTTP-01` challenge.

> [@shot](#):
>
> how does LE access a secure URL that has no cert in order to generate the initial cert

It is part of the [acme-tls/1 Protocol Definition](https://tools.ietf.org/html/rfc8737#section-4). This is very useful in scenarios where you may not have port 80 available.

> While this protocol uses X.509 certificates, it does not use the authentication method described in [[RFC5280](https://tools.ietf.org/html/rfc5280)] and, as such, does not require a valid signature on the provided certificate nor require the TLS handshake to complete successfully.

---

<div class="post-metadata">

**Author:** ![shot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/shot/32/2312_2.png) [@shot](https://community.traefik.io/u/shot)\
**Post date:** [July 1, 2020, 6:51pm UTC](https://community.traefik.io/t/redirect-http-to-https-which-approach-is-better/6720/4 "2020-07-01T18:51:45Z")

</div>

In my experience, both static config values are required for redirection to work. That's **ONE** approach. The **OTHER** approach is described in the blog post I referenced. My question was simply about which approach is better and why. I just don't understand why there are seemingly 2 different means to the same end.

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [July 1, 2020, 6:54pm UTC](https://community.traefik.io/t/redirect-http-to-https-which-approach-is-better/6720/5 "2020-07-01T18:54:33Z")

</div>

I know you were not replying to me as I posted in the same minute. But an answer for you none the less.

> [@shot](#):
>
> just don't understand why there are seemingly 2 different means to the same end.

From the 2.2 release post:

> As a result, you told us that the configuration ended up being a bit too verbose, and that you're missing some sort of redirects on Entrypoints, as we had something similar with Traefik 1.x.
> 
> For that reason, we introduced the concepts of Entrypoint redirects, and default router configuration.

---

<div class="post-metadata">

**Author:** ![shot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/shot/32/2312_2.png) [@shot](https://community.traefik.io/u/shot)\
**Post date:** [July 1, 2020, 7:03pm UTC](https://community.traefik.io/t/redirect-http-to-https-which-approach-is-better/6720/6 "2020-07-01T19:03:12Z")

</div>

Ok, thanks for the clarification, @cakiwi. So basically, the blog post is outdated with regard to Traefik 2.2. Got it.

> [@cakiwi](#):
>
> You can specify either [httpChallenge](https://docs.traefik.io/https/acme/#httpchallenge) or tlsChallenge([Traefik Let's Encrypt Documentation - Traefik](https://docs.traefik.io/https/acme/#tlschallenge)) for the certificate resolver.

Aha, I didn't' catch that. So I should enable `http --> https redirect` and then specify **tlsChallenge** - not **httpChallenge**.

> [@cakiwi](#):
>
> Don't forget dnsChallenge too.

Just so I'm clear on this, you're saying that's an alternative approach to http or tlsChallenge, right? Or do I have to enable that as well? I currently get the LE "fake" cert as described in the docs, so I'm guessing it'll work once I disable the staging URL, right?

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [July 1, 2020, 7:08pm UTC](https://community.traefik.io/t/redirect-http-to-https-which-approach-is-better/6720/7 "2020-07-01T19:08:24Z")

</div>

> [@shot](#):
>
> Aha, I didn't' catch that. So I should enable `http --> https redirect` but specify **tlsChallenge** - not **httpChallenge**.

I use tlsChallenge. If you have an entryPoint on port 80 you could stick with httpChallenge too. The only must in terms of letsencrypt is the httpChallenge(HTTP-01) has to be port 80 and the tlsChallenge(TLS-ALPN-01) on port 443. It is really up to you.

> [@shot](#):
>
> Just so I'm clear on this, you're saying that's an alternative approach to http or tlsChallenge, right?

Yes just one of the options you have.

---

<div class="post-metadata">

**Author:** ![shot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/shot/32/2312_2.png) [@shot](https://community.traefik.io/u/shot)\
**Post date:** [July 1, 2020, 8:51pm UTC](https://community.traefik.io/t/redirect-http-to-https-which-approach-is-better/6720/8 "2020-07-01T20:51:48Z")

</div>

> [@shot](#):
>
> If the former and `http --> https` redirection is in place, how can it succeed?

I totally missed this the first time around...

 ![Screen Shot 2020-07-01 at 2.49.32 PM](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/0/031302d7597180286beeea9179814e2d3677637e.png)
