Hello, I'm facing an issue with configuring Traefik to handle redirection and routing rules across multiple containers. I have two applications hosted on different Docker containers and accessed via Traefik:
Application A: Located on the main domain (example.com). I need to redirect requests to the root path (/) to another subdomain (web.example.com) for handling user login. However, after users authenticate, they should be able to access specific paths like /app and /callback on example.com without being redirected again.
Application B: Hosted on web.example.com, this application handles the authentication process and other UI elements.}
I'm using Traefik v2.x, and I attempted to set up the rules as follows:
# Configuration for Application A on `example.com`
labels:
- "traefik.enable=true"
- "traefik.http.routers.app-a.rule=Host(`example.com`) && (PathPrefix(`/callback`) || PathPrefix(`/app`))"
- "traefik.http.routers.app-a.entrypoints=websecure"
- "traefik.http.routers.app-a.tls=true"
- "traefik.http.routers.app-a.tls.certresolver=myresolver"
- "traefik.http.services.app-a.loadbalancer.server.port=4000"
# Configuration for Application B on `web.example.com`
labels:
- "traefik.enable=true"
- "traefik.http.routers.app-b.rule=Host(`web.example.com`)"
- "traefik.http.routers.app-b.entrypoints=websecure"
- "traefik.http.routers.app-b.tls=true"
- "traefik.http.routers.app-b.tls.certresolver=myresolver"
- "traefik.http.services.app-b.loadbalancer.server.port=3000"
Issue: The rules work to redirect the root (/) to web.example.com for authentication, but after users authenticate, routes like /app and /callback on example.com also redirect to the subdomain instead of staying on example.com or I get a 404 page not found error because the route may have parameters example.com/callback?code=xyz
Can someone please help me, some plugin to fix this?
Hi @bluepuma77, thank you very much for your suggestion. I implemented your recommendation along with some other details I had internally in the way my apps worked (there was some internal redirection that I hadn't noticed) and it worked perfectly. I was able to achieve the desired routing behavior. Thanks again for your help, I really appreciate it!