Hi,
I have some very similar redirects in many places that i would like to make a bit more generic by replacing with an include. This would require substr() or something similar on the {host} placeholder. Is this possible?
Current
redir 302 {
if {remote} starts_with "10.0"
/ https://service.domain.com{uri}
}
What i want
redir 302 {
if {remote} starts_with "10.0"
/ https://substr({host},2){uri} #Remove 2 first letters from the {host}
}
The idea is that if i had a https://e-service.domain.com tab open on my phone while out and return to home, it redirects to https://service.domain.com which doesn’t require authentication.
Sorry to say, but there is no functionality to configure string manipulation of placeholders.
Could I ask what the use case would be? Specifically, if you’re intending to use this as a generic redirect for more than one site definition, how would you structure that to avoid having to hardcode the destination hostnames as site labels anyway?
The sites without e- (as in external) are only accessible from the local network and redirect to e- when accessed from the outside. When e- sites are accessed internally they are redirected to the non-e counterpart to avoid having to log in. If there was basic string manipulation i could just import redirect in each e-site and avioid 3 lines of config.
Ahh, gotcha. Sorry I couldn’t bring you a better answer.
There’s a heavily work-in-progress PR over at the Github page for Caddyfile-wide “if” statements which might possibly one day support arbitrarily extracting this information via regex.