Caddy supports redir
directive that allows to perform a redirect while preserving the URI part:
redir /vl1/* /scm/hg/{uri} 302
It works fine as long as the destination URI matches the same pattern, e.g. /scm/hg/vl1/*
.
But how to redirect the ‘splat’ part of the source URI? For instance, /vl1/*
URI should be redirected to /scm/hg/volumes/1/*
. How to capture the value of the splat part in the destination URL?
My attempts so far:
redir /vl1/* /scm/hg/volumes/1/* 302
It does not work because *
symbol in the destination URL is interpreted as a literal character, not a placeholder.
Another approach is:
redir /vl1/* /scm/hg/volumes/1/{uri} 302
But it leads to the wrong result because {uri}
placeholder captures the whole source URI, leading to the wrong destination URI of /scm/hg/volumes/1/vl1/*
instead of just /scm/hg/volumes/1/*
.
I would expect to be able to write something like this:
redir /vl1/* /scm/hg/volumes/1/{splat} 302
where {splat}
is a placeholder that returns the value that was captured by *
in the source URI matcher.
In this way, a URI like /vl1/sample
could be correctly redirected to /scm/hg/volumes/1/sample
, /vl1/nested/sample
to /scm/hg/volumes/1/nested/sample
, and so on.
For instance, Netlify allows such syntax in its _redirects
file format which is super handy and frequently used: Redirect options | Netlify Docs
Is there a way to achieve this with Caddy?