traefik

Redirect non-www to www Traefik v2

4 minute read Published

How to create more timeless URLs using Traefik 2 with Docker labels.

I like cool URIs that don't change so whenever I’m making a new website I make sure I put my web content on the www subdomain where it belongs. This of course leaves the domain apex, or root of the domain, empty and user agents don’t always do what comes so natural to us humans — adding a www in front of a domain name.

Computers get even more clumsy when you add HTTPS into the equation and are working with new technologies. So if you’re looking for cool URIs too here’s how to redirect domain.example to www.domain.example with Traefik v2 over both HTTP and HTTPS using Docker labels in a docker-compose.override.yml YAML file: