1. The problem I’m having:
I want to extract the URL part without the “path” from the response header Location so that I can run another reverse_proxy
to the redirect Link. But I don’t know if it is possible in Caddy, because it seems to me that the only way we can run some functions on string is to use expression
but expression
only return boolean.
Maybe my pseudo code like this will make things clearer
reverse_proxy https://commons.wikimedia.org {
@redirect status 3xx
vars redirHost func(regex({rp.header.Location}, "(http[s]:\/\/[a-zA-Z0-9-.])+(\/[a-zA-Z0-9-\/]+$)" ))[0] # extract everything before path
handle_response @redirect {
reverse_proxy {{vars.redirHost}}
}
}