I'm running Caddy 2 and could not find any documentation on multiple subdomains.
Basically I want to redirect www to non-www. This is due to some people who always type www before a domain which causes a broken page.
Here's my caddyfile:
montanaflynn.com
root * /var/www/html
file_server
Thanks, excited to start using caddy but it seems like all the docs / issues I found were outdated.
It would look like this:
montanaflynn.com {
root * /var/www/html
file_server
}
www.montanaflynn.com {
redir * https://{http.request.host.labels.1}.{http.request.host.labels.0}{path}
}
Here we're using request placeholders for the redirect, so that if you have multiple sites, you can just add them to the site block, for example www.montanaflynn.com, www.example.com {.
You could just hard-code the redirect destination if you prefer, i.e.
redir * https://montanaflynn.com{path}
Thanks @francislavoie ! And you can actually omit the wildcard matcher (*) in these cases, since the next argument does not look like a path matcher (does not start with /). It is a matter of preference.
The new docs site will be live in a few hours which will have the new Caddyfile docs, check them out @montanaflynn !
Most helpful comment
It would look like this:
Here we're using request placeholders for the redirect, so that if you have multiple sites, you can just add them to the site block, for example
www.montanaflynn.com, www.example.com {.You could just hard-code the redirect destination if you prefer, i.e.