I have this redirect working in V1:
rewrite /z/ {
r (.*)
to /{1}.zip
}
So “/z/file” → “file.zip”
No idea how to do it in V2.
Any help.
Thanks
I have this redirect working in V1:
rewrite /z/ {
r (.*)
to /{1}.zip
}
So “/z/file” → “file.zip”
No idea how to do it in V2.
Any help.
Thanks
try_files
is what you’re looking for
Much simpler to do that in v2.
Edit: Scratch that, I somewhat misread the question.
You need something like this:
@zips {
path_regexp zip ^/z/(.*).zip
}
rewrite @zips {http.regexp.zip.1}.zip
This makes a request matcher using a regexp, naming the regexp zip
so you can refer to the results later, then rewrites if it matches, to the first capture group.
Many thanks.
Working now, much easier in V1
v1’s approach was much more limited though. It was impossible to match on arbitrary requests and handle them in arbitrary ways. v2 makes that all possible.
Glad that solved it for you!
I don’t believe the v1 example given, in fact, has the behaviour specified (/z/file
→ /file.zip
).
Strictly speaking, this matches the v1 example’s behaviour more accurately.
rewrite /z/* {path}.zip
I note that the regex used in the v1 example in fact matches anything, capturing the entire URI, and is rewritten to, effectively, /{uri}.zip
, although {path}
is better to append a file extension to.
Note how in @francislavoie’s example, he changed the regex from (.*)
to ^/z/(.*).zip
, constraining the capture group to exclude the prefix.
(Francis, are you sure it should only match on a pre-existing .zip
if we’re appending one? Doesn’t seem to match the example OR the given desired behaviour.)
I agree with Whitestrake. How did that ever work?
If you don’t want to use a regex, maybe just strip the prefix and then add the suffix, something like:
route /z/* {
uri strip_prefix /z
rewrite {path}.zip
}
(just spitballing here)
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.