You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oh right. The other details is the path matcher matches case-insensitively by converting the request path to lowercase, which means you need to write your matcher with lowercase characters as well to match it (including the variable contents). So if you change your variable to 2024-mar-21 it should work.
The tricky part is we lowercase the path during the provisioning phase (at server/config start) to avoid needing to do it on every request (saving a few nanoseconds at most on each request). This means that any dynamic parts of the path don't get lowercased since it happens before replacing the placeholders.
This also means that the placeholder itself must also be lowercase 😬 so you can't have uppercase characters in the placeholder/variable name 🤦♂️ I'd call this part a bug. Obviously the only fix is to move the lowercasing to after replacing any placeholders, which would be a slight performance hit for everyone even if they don't use placeholders. Or in provisioning we could do a smarter lowercase to only lowercase parts not within placeholders, but I dunno.
The other details is the path matcher matches case-insensitively by converting the request path to lowercase, which means you need to write your matcher with lowercase characters as well to match it (including the variable contents). So if you change your variable to 2024-mar-21 it should work.
Hmmmm - this is interesting - as I'm guessing that would break the redir line using lower case as well - as it'll do filesystem matching on a lower case name - where the actual directory on disk is upper case?
EDIT: This does seem to work - although obviously not ideal:
handle /xplane/charts/* {
vars {
cycle "2024-mar-21"
cycle2 "2024-MAR-21"
}
@daps {
not file
not path /xplane/charts/DAPS-{vars.cycle}/
path_regexp ^/xplane/charts/DAPS.+/(.*)$
}
@ersa {
not file
not path /xplane/charts/ERSA-{vars.cycle}/
path_regexp ^/xplane/charts/ERSA.+/(.*)$
}
redir @daps /xplane/charts/DAPS-{vars.cycle2}/{re.1} permanent
redir @ersa /xplane/charts/ERSA-{vars.cycle2}/{re.1} permanent
file_server {
browse
}
}
Yeah you'd probably have to use 2 different variables in that case I guess. Or you could change to using an expression matcher and do the string comparison yourself, something like this:
Placeholders inside a CEL expression act like a function call so they can't be inlined inside of a string, so concat needs to be used to form the path there. Simple enough though.
Activity
francislavoie commentedon Jun 10, 2024
For ref, context from the forums https://caddy.community/t/rewriting-of-changing-url-paths/24426
The
pathmatcher matches paths exactly, not as a prefix. Do you mean to match/xplane/charts/DAPS-{vars.cycle}/*instead (note the*at the end)?CRCinAU commentedon Jun 10, 2024
Hi @francislavoie - the aim is to:
Redirect a path, say:
/xplane/charts/DAPS-2000-DEC-22/filename.pdfto/xplane/charts/DAPS-2024-MAR-21/filename.pdfThe directory is browseable, but without the
not pathmatcher to the directory listing page, a loop of 301's is entered.If I hard-set the
not pathto the value ofvars.cycleinstead of using the variable, then it works as expected.For the sake of example, with the
not pathhard coded instead of using variables, the following redirects happen:With the
not pathset to include{vars.cycle}, the following redirects happen:I don't believe that using a
/*on the end would negate the infinite redirect loop for a directory listing served by thebrowseoption tofile_server.The
not pathis there to prevent the infinite 301 redirects to the same page.francislavoie commentedon Jun 10, 2024
Oh right. The other details is the
pathmatcher matches case-insensitively by converting the request path to lowercase, which means you need to write your matcher with lowercase characters as well to match it (including the variable contents). So if you change your variable to2024-mar-21it should work.The tricky part is we lowercase the path during the provisioning phase (at server/config start) to avoid needing to do it on every request (saving a few nanoseconds at most on each request). This means that any dynamic parts of the path don't get lowercased since it happens before replacing the placeholders.
This also means that the placeholder itself must also be lowercase 😬 so you can't have uppercase characters in the placeholder/variable name 🤦♂️ I'd call this part a bug. Obviously the only fix is to move the lowercasing to after replacing any placeholders, which would be a slight performance hit for everyone even if they don't use placeholders. Or in provisioning we could do a smarter lowercase to only lowercase parts not within placeholders, but I dunno.
/cc @mholt a decision needs to be made here
CRCinAU commentedon Jun 10, 2024
Hmmmm - this is interesting - as I'm guessing that would break the
redirline using lower case as well - as it'll do filesystem matching on a lower case name - where the actual directory on disk is upper case?EDIT: This does seem to work - although obviously not ideal:
francislavoie commentedon Jun 10, 2024
Yeah you'd probably have to use 2 different variables in that case I guess. Or you could change to using an expression matcher and do the string comparison yourself, something like this:
Placeholders inside a CEL expression act like a function call so they can't be inlined inside of a string, so concat needs to be used to form the path there. Simple enough though.
CRCinAU commentedon Jun 10, 2024
This actually works perfectly. Thanks for this workaround! Gets me one step closer to moving my static site to Caddy :)
Will leave this issue open though, as I believe the original config should actually work.
caddyhttp: lower-case path patterns with placeholders at request time (…
caddyhttp: lower-case path patterns with placeholders at request time (…