# Traefik v2 - is it possible to redirect to https based on host?

**URL:** <https://community.traefik.io/t/traefik-v2-is-it-possible-to-redirect-to-https-based-on-host/9641>\
**Category:** Traefik v2\
**Tags:** middleware\
**Created:** [February 9, 2021, 3:15am UTC](https://community.traefik.io/t/traefik-v2-is-it-possible-to-redirect-to-https-based-on-host/9641 "2021-02-09T03:15:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thecodesucker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/thecodesucker/32/3349_2.png) [@thecodesucker](https://community.traefik.io/u/thecodesucker)\
**Post date:** [February 9, 2021, 3:15am UTC](https://community.traefik.io/t/traefik-v2-is-it-possible-to-redirect-to-https-based-on-host/9641/1 "2021-02-09T03:15:14Z")

</div>

I am easily able to redirect all `http` traffic to `https`, using following args -- it creates a middleware named `redirect-web-to-websecure`:

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

```

But, I wish to achieve following:  
`*.example.com` (external traffic) -\> redirect `http` to `https`  
`*.nas.lan` (internal traffic) -\> redirect `https` to `http` (no redirection will also work)

I can achieve this using IngressRoute in a k3s cluster, but I wish to avoid doing this for all the apps/subdomains and would prefer to have a global solution. How can I do that?

---

<div class="post-metadata">

**Author:** ![thecodesucker](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/thecodesucker/32/3349_2.png) [@thecodesucker](https://community.traefik.io/u/thecodesucker)\
**Post date:** [February 15, 2021, 8:02pm UTC](https://community.traefik.io/t/traefik-v2-is-it-possible-to-redirect-to-https-based-on-host/9641/2 "2021-02-15T20:02:13Z")

</div>

Following chain (see image) gets created, with these two traefik arguments:

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

```

It does following:

1. creates a router
2. creates a middlewhare
3. applies `entrypoint -> router -> middlewhare -> noop-service` globally

See the underlined (in red) rule in the router below, how can I replace it with my own regex?  
Alternatively, how can I create a `HTTP Router` and attach it to a given `Entrypoint`?

 ![image](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/a/af892aec13328aa879a8c4ebaab341f249e7ca47.png)
