In my http://www.domain.com, Only login and register need redir to https ,like this:
http://www.domain.com/login, http://www.domain.com/register redir to https:
how to setup in Caddyfile ?
Hi @goodforever,
Honestly, it’s probably simpler just to have the whole site on HTTPS. It certainly won’t hurt. Caddy can definitely do what you’re asking, though.
You can use if statements with redir
. You’ll want to compare the {path}
placeholder to the locations you want to redirect. You’ll also need to change if_op
if you’ve got multiple locations - by default, it’s AND, you want OR.
redir {
if_op or
if {path} starts_with /login
if {path} starts_with /register
/ https://example.com{uri}
}
https://caddyserver.com/docs/redir
https://caddyserver.com/docs/placeholders
Thanks, Is it like the following ?
https://www.mydomain.com {
gzip
tls username@mydomain.com
proxy / http://myservice:8080
}
http://www.mydomain.com {
redir {
if_op or
if {http://www.mydomain.com/login} starts_with /login
if {http://www.mydomain.com/register} starts_with /register
/ https://www.mydomain.com{uri}
}
gzip
proxy / http://myservice:8080
}
The if
statements look incorrect - the URL doesn’t go there, the placeholder does. Check the placeholders docs again - the one you want is {path}
, used like: if {path} starts_with ...
Looks good otherwise!
{path} , Thanks!
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.