Cannot get global http to https redirection to work

Hi, I'm new to Traefik and I can't configure it for HTTP to HTTPS redirection, and www to no-www redirection.
I have read almost every doc and forum, and I think I might have a problem with the regexp.

I have a docker-compose file in where I describe (among many) two services: Traefik, and a Nginx that hosts a web page. It is not the only web page under the domain (lets call it, but every web page works fine, under
The domain is certified with Letsencrypt.

My issues:
-Whenever I type, it redirects me to a 404 not found.
-Whenever I type, it redirects me to a 404 not found (same as above).
So, http as well as www point me to a 404 not found.

My desired solution:
I would like the URL to be transformed to
I would like to set things with middlewares, since that is the approach that gave me the closest to a solution. But any help is appreciated.

This is the docker compose file.

    image: "traefik:v2.10"
      - "--log.level=TRACE"
      - "--api.dashboard=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=true"

      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"

      - "--certificatesresolvers.myresolver.acme.tlschallenge=true"
      - ""
      - ""
      - "--entrypoints.web.http.tls.certresolver=myresolver"
      - "80:80"
      - "443:443"
      - "./letsencrypt:/letsencrypt"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "traefik.enable=true"
      - "traefik.http.middlewares.stripprefix.stripprefix.prefixes=/traefik"
      - "traefik.http.routers.traefik.rule=Host(``) && (PathPrefix(`/traefik`) || Headers(`Referer`, ``))"
      - "traefik.http.routers.traefik.entrypoints=websecure"
      - "traefik.http.routers.traefik.tls.certresolver=myresolver"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.middlewares=traefik-auth, traefik-stripprefix, non_www, https_redirect"

        #two middleware declaration: https_redirect, that redirects http to https. And non_www, that redirects to
      - "traefik.http.routers.http_catchall.rule=HostRegexp(`{any:.+}`)"
      - "traefik.http.routers.http_catchall.entrypoints=web"
      - "traefik.http.routers.http_catchall.middlewares=https_redirect"
      - "traefik.http.middlewares.https_redirect.redirectscheme.scheme=https"
      - "traefik.http.middlewares.https_redirect.redirectscheme.permanent=true"
      - "traefik.http.middlewares.non_www.redirectregex.regex=^(http|https)://(?:www\\.)?(.+)"
      - "traefik.http.middlewares.non_www.redirectregex.replacement=https://$${2}"
      - "traefik.http.middlewares.non_www.redirectregex.permanent=true"

    image: nginx:latest
    restart: always
      - ../ofivirtual/src/oficina-virtual/www/:/usr/share/nginx/html
      - "traefik.enable=true"
      - "traefik.http.routers.nginx.rule=Host(``)"
      - "traefik.http.routers.nginx.entrypoints=websecure"
      - "traefik.http.routers.nginx.tls.certresolver=myresolver"

      - "traefik.http.routers.nginx.middlewares=https_redirect@docker,non_www@docker"

I just want to know if this is the correct approach or if I'm missing something important.

How about going the easy route and setting the redirect on entrypoint? (Doc)

I tried that. What happens then is, page goes to a 404 not found, and browser says 'Connection not secure'.
Do you know why that could be? Maybe I am not configuring correctly the certificate for the http? Could that be necessary?
Thank you in advance.

See simple Traefik example.

You can’t use PathPrefix with Traefik Dashboard, it expects to be on "root" path, use a sub-domain.

Thank you for pointing that out, I appreciate it. However, that is not the main issue of this discussion.