Redirect if the domain does not exist

Hi!

Guys, is it possible to do a global redirect in cases where there is no domain, for example, if I have nothing on mydomain.com -> google.com, or non-existent.mydomain.com -> google.com - now Traefik will just open a 404 page, if subdomain is non-existent it will be with certificate warning -> 404, if mydoman.com it's just 404... and etc. is it possible to add such a redirect?

I remember that such a redirect is possible, for example, in the nginx proxy manager.

Thanks.

Hey guys! Any suggestions? Thanks in advance!

I like to know this as well, any suggestions what to put where for this ?

Use middleware in dynamic config:

# docker-compose.yml
services:
  catchall:
    image: traefik/whoami:v1.8
    hostname: catchall
    networks:
      - proxy
    labels:
      - traefik.enable=true
      - traefik.http.routers.catchall.rule=HostRegexp(`{host:.+}`)
      - traefik.http.routers.catchall.priority=1
      - traefik.http.routers.catchall.middlewares=redirectall
      - traefik.http.middlewares.redirectall.redirectregex.regex=.*
      - traefik.http.middlewares.redirectall.redirectregex.replacement=https://example.com
      - traefik.http.services.catchall.loadbalancer.server.port=80

If no other router matches the request, this router is used as a fallback with the lowest priority.

This works for all http requests. It only works for https, when you have explicit certs for domains and/or sub-domains or use sub-domains with a wildcard cert.

Cool thanks!

Can we make it's own redirect when traefik is visited by it's IP itself?

A generic redirect will probably only work for http, as for https you need a TLS cert and I don't think you can get one for an IP address only. So browsers will throw an error, for command line tools like curl you can set options to ignore.

Thanks!

Yes that is my concern as well. I was hoping to get some solution there, maybe just firewall :slight_smile: