No worries, this is actually pretty simple, conceptually - you want both HTTP and HTTPS versions of your site to have the same behaviour (redirect to https://www). The Caddyfile plays out equally simply:
Caddy will handle the HTTPS site automatically, like any other Automatic HTTPS site.
You can simply list every site, HTTP or HTTPS version, in the site label list at the top - grouping all sites with the same redirection target together.
This is the initial solution this works great if I just wanted to move naked https domains to www . Now if i wanted to do domain redirect from one domain to do it on the caddy server. Is there a way to query an api to get the domain redirect it supposed to go.
http://, https:// {
redir {
if {host} not_starts_with www.
to https://www.{host}{uri}
}
tls email@example.com
tls {
max_certs 10
}
}
Using http://, https:// instead of :80, :443 makes it more explicit what you’re intercepting and allows for whatever ports you’re listening on to respond appropriately.
Adding the if check to the redir will prevents an inappropriate redirection in the case of a request for a domain you don’t actually serve.
You can always extend Caddy with a plugin to create this behaviour, but the current feature set has no such functionality.
The closest would be to simply proxy the request, either to another web server or directly via FastCGI, to a server running a scripting language. Have a PHP index file that checks the requested host and issues the redirect header appropriately, or an error otherwise.