I am trying to configure Caddy to do the following:
- redirect all requests for http://example.com → http://www.example.com (NOT changing scheme to HTTPS)
- redirect all requests for https://example.com → https://www.example.com (already on HTTPS)
I can get the second half to work with the automatic SSL via Lets Encrypt. The problem, however, is that Caddy is forcing the HTTPS redirection which is unwanted. Here’s my Caddyfile so far:
:443
gzip
log /var/log/caddy.log
tls {
max_certs 10
}
redir 301 {
{scheme}://www.{host}{uri}
}
We’ll be switching the max_certs directive for getting an approved list of hosts from an API endpoint we have, but during testing the max_certs suffices.
How can I suppress the HTTP → HTTPS redirection?