Redirect to subpath and http to https


i know how to redirect every request from to

But how do i combine this if i want every request to redirected to

I tried different sinppets here from the forum but can't get it to work.

Any help is welcome.

Hi @lachnerd

Do you want just the http of to be redirected or would you want to be redirected also ?

If it is only you would want a redirectRegex middleware before the redirectScheme on a router on the http entryPoint.

If you are redirecting everything to https anyway then a route using the https entryPoint and redirectRegex should be sufficient.

The route handling /subpath/ would need to remain at a higher priority then the redirectRegex or you would keep matching the same redirect rule when the client gets redirected.

As you know posting your configuration will help.

1 Like

Hi @cakiwi,

i want everything redirected to https and one specific host/service to


  checkNewVersion = true
    address = ":80"
    address = ":443"
    address = ":8080"
    watch = true
    refreshSeconds = 15
    intervalPoll = false
    exposedByDefault = false
    filename = "${config_path}/dynamic_conf.toml"
  dashboard = true
  email = ""
  storage = "${traefik_certs_path}/acme.json"
    provider = "route53"
    delayBeforeCheck = 5


# redirect
    scheme = "https"
    permanent = true

   #default traefik:traefik, dollar signs escaped with double dollar-signs
   # for generating new basic auth string use 'htpasswd -n -C 5 -B <user>'
   #users = ["BASIC_AUTH"]
   usersFile = "usersfile"

# gzip compression

traefik labels:

traefik.enable: true 
traefik.http.routers.traefik-web.entrypoints: web
traefik.http.routers.traefik-web.rule: Host(``)
traefik.http.routers.traefik-web.middlewares: redirect@file #defined in dynamic_conf.toml
traefik.http.routers.traefik-websecure.entrypoints: websecure
traefik.http.routers.traefik-websecure.tls.certresolver: aws
traefik.http.routers.traefik-websecure.rule: Host(``)[0].sans: '*'[0].main: ''
traefik.http.routers.traefik-websecure.service: api@internal
traefik.http.routers.traefik-websecure.middlewares: url-com-auth@file #defined in dynamic_conf.toml 8080

service labels (that should be redirected to subpath):

traefik.enable: true web redirect@file #defined in dynamic_conf.toml Host(``) websecure errorhandler@file,compress@file #defined in dynamic_conf.toml true 8080 Host(``)

I thought modifying Host(``)

to Host(``) && PathPrefix(`/subpath/`)

Would to the trick, but it only works for directly opened not for or

So how do i redirect/prioritize a redirection here ?


First if you are redirecting everything on your web entry point to https may I suggest EntryPoint Redirection and entrypoint TLS (Traefik v2.2). It saves a catchall rule or a rule and middleware per service. I find it a lot cleaner to work with.

I would go about it like:

# This would _only_ match Host(``) && Path(`/`) true app-websecure-redir ".*"
# Your router is here Host(``) && PathPrefix(`/subpath/`)

I hope this helps, if there is anything more complex like redirecting anything that does NOT have /subpath/ or requires passing the original path to subpath then the redirectregex can be updated.

As I got to the end of this I thought if your app returns the correct path on the request you could just do an addPrefix.

# This would _only_ match Host(``) && Path(`/`) true app-websecure-addsub /subpath
# Your router is here Host(``) && PathPrefix(`/subpath/`)

Hi @cakiwi,

thanks a lot i will try that.