Hello I'm trying to redirect every non www url to a www url
Following the guide redacted by the moderator kakiwi there => Redirect from non-www to www with traefik 2
My config was running as expected just using host without www but we decided to redirect everything on www. url ...
I've two docker-compose.yml in /aFolder/traefik/docker-compose.yml
And the second in /aFolder/myApp/docker-compose.yml
The traefik/docker-compose.yml :
...
labels:
...
# low priority rule for otherwise unmatched www. host prefixes
# without this it is constant redirect
- "traefik.http.routers.unmatchedwww.rule=HostRegexp(`{name:^www\\..*}`)"
- "traefik.http.routers.unmatchedwww.service=noop@internal"
- "traefik.http.routers.unmatchedwww.priority=2"
# lowest priority catchall rule, will add/replace www. host portion
- "traefik.http.routers.matchlast.rule=PathPrefix(`/`)"
- "traefik.http.routers.matchlast.priority=1"
- "traefik.http.routers.matchlast.middlewares=addwww"
- "traefik.http.middlewares.addwww.redirectregex.regex=^https://(?:www\\.)?(.*)"
- "traefik.http.middlewares.addwww.redirectregex.replacement=https://www.$$1"
myApp/docker-compose.yml :
version: "3.8"
services:
my-app:
container_name: my-app
image: my-app
build:
context: .
dockerfile: Dockerfile
networks:
- traefik-network
ports:
- ":80"
labels:
- "traefik.enable=true"
- "traefik.http.routers.my-app.rule=Host(`www.my-app.com`)"
- "traefik.http.routers.my-app.tls.domains[0].main=my-app.com"
- "traefik.http.routers.my-app.tls.domains[0].sans=www.my-app.com"
- "traefik.http.routers.my-app.service=my-app"
- "traefik.http.routers.my-app.entrypoints=websecure"
- "traefik.http.services.my-app.loadbalancer.server.port=80"
- "traefik.http.routers.my-app.tls=true"
- "traefik.http.routers.my-app.tls.certresolver=myresolver"
- "traefik.http.services.my-app.loadbalancer.passhostheader=true"
- "traefik.docker.network=traefik-network"
restart: unless-stopped
networks:
traefik-network:
external: true
Traefik dashboard available,
www.my-app.com available
my-app.com => 404 page not found
docker logs traefik :
IP - - [14/Dec/2023:15:29:50 +0000] "GET / HTTP/2.0" 404 19 "-" "-" 912 "-" "-" 0ms
IP - - [14/Dec/2023:15:29:50 +0000] "GET /favicon.ico HTTP/2.0" 404 19 "-" "-" 913 "-" "-" 0m
I've been trying to make this work for two days now. Any help would be greatly appreciated
Thanks in advance