# Problem with redirection http to https. I lose the port of web-secure

**URL:** <https://community.traefik.io/t/problem-with-redirection-http-to-https-i-lose-the-port-of-web-secure/2933>\
**Category:** Traefik v2\
**Tags:** file\
**Created:** [November 14, 2019, 9:22am UTC](https://community.traefik.io/t/problem-with-redirection-http-to-https-i-lose-the-port-of-web-secure/2933 "2019-11-14T09:22:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmramirez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jmramirez/32/1100_2.png) [@jmramirez](https://community.traefik.io/u/jmramirez)\
**Post date:** [November 14, 2019, 9:22am UTC](https://community.traefik.io/t/problem-with-redirection-http-to-https-i-lose-the-port-of-web-secure/2933/1 "2019-11-14T09:22:08Z")

</div>

Hi to all!

I have a port problem in Traefik v2.0 with redirecction http to https. This is my config:

```auto
#Static conf Traefik
#traefik.toml

[entryPoints.web]
   address = ":84"

[entryPoints.web-secure]
   address = ":444"

[entryPoints.traefik]
   address = ":8082"

.....

# Dinamic conf Traefik
# dynamic-conf.toml

[http.routers]
   [http.routers.router0]
      rule = "Host(`myhost`)"
      entrypoints = ["web"]
      priority = 100
      service = "jupiter-web"
      middlewares = ["redirect"]

   [http.routers.router1]
      rule = "Host(`myhost`)"
      service = "jupiter-web"
      entrypoints = ["web-secure"]
      [http.routers.router1.tls]

[http.middlewares]
   [http.middlewares.redirect.redirectScheme]
      scheme = "https"
      permanent = true

[http.services]
   [[http.services.jupiter-web.loadBalancer.servers]]
      url = "http://192.168.1.200:84"
      passHostHeader = true

[[tls.certificates]]
   certFile = "/certs/domain.crt"
   keyFile = "/certs/sslkey.key"

```

Web-secure its ok. When I go to **https:myhost:444** the cerfificates works and the web page of destiny on my service its ok.

But when I go to **http:myhost:84** the middlewares redirect to **https:myhost**. I lose the 444 port and the conection its not secure. The certificates SSL fails obviusly.

Can you help me with the problem?

Thank in advance!!

Regards,  
Jose Manuel

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [November 14, 2019, 10:06am UTC](https://community.traefik.io/t/problem-with-redirection-http-to-https-i-lose-the-port-of-web-secure/2933/2 "2019-11-14T10:06:19Z")

</div>

Hello,

you have to use [redirectregex](https://docs.traefik.io/v2.0/middlewares/redirectregex/) instead of redirectScheme.

---

<div class="post-metadata">

**Author:** ![jmramirez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jmramirez/32/1100_2.png) [@jmramirez](https://community.traefik.io/u/jmramirez)\
**Post date:** [November 14, 2019, 10:11am UTC](https://community.traefik.io/t/problem-with-redirection-http-to-https-i-lose-the-port-of-web-secure/2933/3 "2019-11-14T10:11:35Z")

</div>

Hi Idez!!

Can you post a sample for this redirectregex based on my config?

Thank you!! 🙌🏼

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [November 14, 2019, 10:25am UTC](https://community.traefik.io/t/problem-with-redirection-http-to-https-i-lose-the-port-of-web-secure/2933/4 "2019-11-14T10:25:02Z")

</div>

Something like that:

```auto
[http.middlewares]
  [http.middlewares.redirect.redirectRegex]
    regex = "^http:\/\/([\w\._-]+)(:\d+)?(.*)$"
    replacement = "https://${1}:444/${3}"
    permanent = true

```

---

<div class="post-metadata">

**Author:** ![jmramirez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jmramirez/32/1100_2.png) [@jmramirez](https://community.traefik.io/u/jmramirez)\
**Post date:** [November 14, 2019, 11:09am UTC](https://community.traefik.io/t/problem-with-redirection-http-to-https-i-lose-the-port-of-web-secure/2933/5 "2019-11-14T11:09:50Z")

</div>

Hi!

I test it your solution but i have a parsing error on your regex. Dont work. I try this other one but still doesnt work.

```auto
[http.middlewares]
   [http.middlewares.redirect.redirectRegex]
      regex = "^http://myhost/(.*)"
      replacement = "https://myhost:444/${1}"
      permanent = true

```

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [November 14, 2019, 11:10am UTC](https://community.traefik.io/t/problem-with-redirection-http-to-https-i-lose-the-port-of-web-secure/2933/6 "2019-11-14T11:10:50Z")

</div>

```auto
[http.middlewares]
   [http.middlewares.redirect.redirectRegex]
      regex = "^http://myhost:84/(.*)"
      replacement = "https://myhost:444/${1}"
      permanent = true

```

---

<div class="post-metadata">

**Author:** ![jmramirez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jmramirez/32/1100_2.png) [@jmramirez](https://community.traefik.io/u/jmramirez)\
**Post date:** [November 14, 2019, 11:14am UTC](https://community.traefik.io/t/problem-with-redirection-http-to-https-i-lose-the-port-of-web-secure/2933/7 "2019-11-14T11:14:30Z")

</div>

Wao!! Sorry! I forget put the 84 port on URL. Now Its works!!

Thanks for your help!!!!🙌🏼
