I guess something like this:
@acceptsWebp {
header Accept *image/webp*
path_regexp webp ^(.+)\.(jpg|jpeg|png)$
}
handle @acceptsWebp {
@hasWebp file {re.webp.1}.webp
rewrite @hasWebp {re.webp.1}.webp
}
It’s a bit funky, but it needs to be done this way (two separate matchers, cascading with a handle
) because matchers in the same set aren’t guaranteed to run in any particular order, therefore you need to split them up to make sure they run in order. This matters because you need to use the regexp result in the file
matcher.
I guess you could try to do another rewrite like this, handle
blocks are mutually exclusive so you don’t need to worry they’ll step on eachother’s toes, but you might need to wrap the whole thing in a route
to make sure the priority (which of the two file types you prefer) is proper (i.e. check if accepts avif first, then webp, I guess).
I guess, but it would mean serving a redirect instead of a rewrite, which is much slower because it involves an extra round-trip. There’s no other way to manipulate the URL in the browser at this layer.