D
Dokployโ€ข7mo ago
Graekor

Issue on redirects

Hello ! I'm new with dokploy and I tried to setup a redirect for my website in the dokploy UI system. I'm just trying to do a https://bleguen.fr to https://www.bleguen.fr but when I do this. I do have a Bad gateway. I tried the redirects presets. Anyone have and idea ? Thanks a lot
4 Replies
British
Britishโ€ข7mo ago
nice portfolio man
Graekor
GraekorOPโ€ข7mo ago
Thanks a lot ๐Ÿ™‚
Catur
Caturโ€ข7mo ago
Hi Graekor, to redirect https://bleguen.fr/ to https://www.bleguen.fr/, you can add a middleware to your container's Traefik configuration file. Find your container's Traefik configuration file in /dashboard/traefik > ๐Ÿ“ dynamic, then find the file with the same name as your application container. Then add middleware, like the example below:
http:
...
middlewares:
redirect-www: # ๐Ÿ‘ˆ๐Ÿป you can give it a name as you wish
redirectRegex:
regex: "https://bleguen.fr/"
replacement: "https://www.bleguen.fr/"
...
http:
...
middlewares:
redirect-www: # ๐Ÿ‘ˆ๐Ÿป you can give it a name as you wish
redirectRegex:
regex: "https://bleguen.fr/"
replacement: "https://www.bleguen.fr/"
...
Then add the middleware that you just created above, to your application router config, just add it to entryPoints = websecure only.
...
routers:
your-container-router:
rule: Host(`your.domain.name`)
service: your-container-service
middlewares:
- redirect-to-https
entryPoints:
- web
your-container-router-websecure:
rule: Host(`your.domain.name`)
service: your-container-service
middlewares:
- redirect-www # ๐Ÿ‘ˆ๐Ÿป add middleware with the name of the middleware
entryPoints:
- websecure
tls:
certResolver: letsencrypt
...
...
routers:
your-container-router:
rule: Host(`your.domain.name`)
service: your-container-service
middlewares:
- redirect-to-https
entryPoints:
- web
your-container-router-websecure:
rule: Host(`your.domain.name`)
service: your-container-service
middlewares:
- redirect-www # ๐Ÿ‘ˆ๐Ÿป add middleware with the name of the middleware
entryPoints:
- websecure
tls:
certResolver: letsencrypt
...
For more tips: Tip 1: you can also add middleware configuration to the middleware.yml file in /dashboard/traefik > ๐Ÿ“ dynamic, then add to the routers as per the steps above. Tip 2: In addition to adding to the configuration file, if you have a compose file for your application, you can also add it to your application's compose file, by adding the following label to the compose file:
# Redirect with domain replacement
labels:
- "traefik.http.middlewares.redirect-www.redirectregex.regex=https://bleguen.fr/"
- "traefik.http.middlewares.redirect-www.redirectregex.replacement=https://www.bleguen.fr/"
# Redirect with domain replacement
labels:
- "traefik.http.middlewares.redirect-www.redirectregex.regex=https://bleguen.fr/"
- "traefik.http.middlewares.redirect-www.redirectregex.replacement=https://www.bleguen.fr/"
Below for reference: https://doc.traefik.io/traefik/routing/routers/#middlewares
Graekor
GraekorOPโ€ข7mo ago
Thanks you for the answer, after trying everything you said, it is working, I set the domain to bleguen.fr and not www.bleguen.fr but when i do so with the redirect then I have 404 page not found When I add a second domain 'www.bleguen.fr' it's working but I don't think that's a good practice

Did you find this page helpful?