https and www redirections in Compose services
What problem will this feature address?
Unlike application services, compose services do not have a "Redirects" setting, allowing the users to redirect from non-www to www for example. Therefore, I cannot have a redirection from domain.com to www.domain.com.
Describe the solution you'd like
A "Redirects" setting in compose services, allowing the user to add a redirection, like in the application services.
Describe alternatives you've considered
I did not find any alternative solutions or workaround so far.
Additional context
No response
Will you send a PR to implement it?
Maybe, need help
When you go to 'Traefik File System' you could add a middleware in middlewares.yml like this:
redirect-to-www:
redirectRegex:
regex: ^https://domain\.com/?$
replacement: https://www.domain.com
permanent: true
In your compose file you would then need to add this label to your service:
labels:
- traefik.http.routers.<service_name>.middlewares=redirect-to-www@file
The service_name can be found if you click 'Preview Compose' in the top right of the provider section (search for this line
- traefik.http.routers.<container_name>-<some_number>-websecure.service=<container_name>-<some_number>-websecure)
When you go to 'Traefik File System' you could add a middleware in middlewares.yml like this:
redirect-to-www: redirectRegex: regex: ^https://domain\.com/?$ replacement: https://www.domain.com permanent: trueIn your compose file you would then need to add this label to your service:
labels: - traefik.http.routers.<service_name>.middlewares=redirect-to-www@fileThe service_name can be found if you click 'Preview Compose' in the top right of the provider section (search for this line
- traefik.http.routers.<container_name>-<some_number>-websecure.service=<container_name>-<some_number>-websecure)
Is this really a viable solution? How are you dealing with labels added by dokploy and the container name randomization?
When adding labels yourself those will just get appended to the ones dokploy generated. Container name is randomized on creation but then stays the same, so you can safely copy the service name from the compose preview as described
It would be great to have the one-click option in Compose.