WebP rewrite rule ignored after adding custom headers for images

#1
The usual rewrite rule that I stick inside the "/" static context works fine by itself:

RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{DOCUMENT_ROOT}/$1.webp -f
RewriteRule (.+)\.(jpe?g|png)$ $1.webp [T=image/webp,E=accept:1]


But as soon as I add custom Cache-Control headers for images in another static rule (going by the guides), the webp rewrite rule no longer gets obeyed and I never again see a webp image get loaded. Here's what I have for the other context:

context exp:^.*(a?png|gif|jpe?g|svg|webp)$ {
location $DOC_ROOT/$0
allowBrowse 1
note Cache-Control for images. Store for 28 days before re-validating.
extraHeaders <<<END_extraHeaders
unset Last-Modified
unset Cache-control
set Cache-control max-age=2419200, must-revalidate
END_extraHeaders


Re-arranging the "Order" does nothing. Enabling "Inherit Rewrite Rules" does nothing. Do I need to write another rule in this more-specific context? Can a regex wizard help me figure out what that rule would be?
 
#3
Just looking into this now - this is a simple test page containing one jpeg image (and its webp copy in the same dir). There's no favicon though the browser looks for it, that's why it appears in the logs below.

So, with both rewrite rules mentioned above, this is all I get in the log:

2020-06-06 11:51:05.116635 [INFO] [178.20.203.17:50986:HTTP2-15#depth.gallery] [REWRITE] strip base: '/' from URI: '/'
2020-06-06 11:51:05.116720 [INFO] [178.20.203.17:50986:HTTP2-15#depth.gallery] [REWRITE] Rule: Match '' with pattern '^/?(.*)', result: 2
2020-06-06 11:51:05.116740 [INFO] [178.20.203.17:50986:HTTP2-15#depth.gallery] [REWRITE] Cond: Compare 'on' with pattern 'on', result: 0
2020-06-06 11:51:05.116744 [INFO] [178.20.203.17:50986:HTTP2-15#depth.gallery] [REWRITE] Rule: Match '' with pattern '(.+)\.(jpe?g|png)$', result: -1
2020-06-06 11:51:05.461945 [INFO] [178.20.203.17:50986:HTTP2-19#depth.gallery] [REWRITE] strip base: '/' from URI: '/favicon.ico'
2020-06-06 11:51:05.461982 [INFO] [178.20.203.17:50986:HTTP2-19#depth.gallery] [REWRITE] Rule: Match 'favicon.ico' with pattern '^/?(.*)', result: 2
2020-06-06 11:51:05.461988 [INFO] [178.20.203.17:50986:HTTP2-19#depth.gallery] [REWRITE] Cond: Compare 'on' with pattern 'on', result: 0
2020-06-06 11:51:05.461993 [INFO] [178.20.203.17:50986:HTTP2-19#depth.gallery] [REWRITE] Rule: Match 'favicon.ico' with pattern '(.+)\.(jpe?g|png)$', result: -1



If I delete the rule which adds the Cache-Control headers to all images, I'm now seeing the webp rewrite in action:

2020-06-06 11:52:17.848713 [INFO] [178.20.203.17:50997:HTTP2-15#depth.gallery] [REWRITE] Rule: Match '' with pattern '^/?(.*)', result: 2
2020-06-06 11:52:17.848719 [INFO] [178.20.203.17:50997:HTTP2-15#depth.gallery] [REWRITE] Cond: Compare 'on' with pattern 'on', result: 0
2020-06-06 11:52:17.848723 [INFO] [178.20.203.17:50997:HTTP2-15#depth.gallery] [REWRITE] Rule: Match '' with pattern '(.+)\.(jpe?g|png)$', result: -1
2020-06-06 11:52:18.058733 [INFO] [178.20.203.17:50997:HTTP2-17#depth.gallery] [REWRITE] strip base: '/' from URI: '/guitars-bg-mob.jpg'
2020-06-06 11:52:18.058780 [INFO] [178.20.203.17:50997:HTTP2-17#depth.gallery] [REWRITE] Rule: Match 'guitars-bg-mob.jpg' with pattern '^/?(.*)', result: 2
2020-06-06 11:52:18.058786 [INFO] [178.20.203.17:50997:HTTP2-17#depth.gallery] [REWRITE] Cond: Compare 'on' with pattern 'on', result: 0
2020-06-06 11:52:18.058791 [INFO] [178.20.203.17:50997:HTTP2-17#depth.gallery] [REWRITE] Rule: Match 'guitars-bg-mob.jpg' with pattern '(.+)\.(jpe?g|png)$', result: 3
2020-06-06 11:52:18.058795 [INFO] [178.20.203.17:50997:HTTP2-17#depth.gallery] [REWRITE] Cond: Match 'image/webp,*/*' with pattern 'image/webp', result: 1
2020-06-06 11:52:18.058813 [INFO] [178.20.203.17:50997:HTTP2-17#depth.gallery] [REWRITE] Cond: test '/home/depth.gallery/public_html/guitars-bg-mob.webp' with pattern '-f', result: 0
2020-06-06 11:52:18.058839 [INFO] [178.20.203.17:50997:HTTP2-17#depth.gallery] [REWRITE] add ENV: 'accept:1'
2020-06-06 11:52:18.058851 [INFO] [178.20.203.17:50997:HTTP2-17#depth.gallery] [REWRITE] Source URI: 'guitars-bg-mob.jpg' => Result URI: 'guitars-bg-mob.webp'
2020-06-06 11:52:18.058855 [INFO] [178.20.203.17:50997:HTTP2-17#depth.gallery] [REWRITE] set forced type: 'image/webp'
2020-06-06 11:52:18.058858 [INFO] [178.20.203.17:50997:HTTP2-17#depth.gallery] [REWRITE] prepend rewrite base: '/', final URI: '/guitars-bg-mob.webp'
2020-06-06 11:52:18.192336 [INFO] [178.20.203.17:50997:HTTP2-19#depth.gallery] [REWRITE] strip base: '/' from URI: '/favicon.ico'
2020-06-06 11:52:18.192377 [INFO] [178.20.203.17:50997:HTTP2-19#depth.gallery] [REWRITE] Rule: Match 'favicon.ico' with pattern '^/?(.*)', result: 2
2020-06-06 11:52:18.192383 [INFO] [178.20.203.17:50997:HTTP2-19#depth.gallery] [REWRITE] Cond: Compare 'on' with pattern 'on', result: 0
2020-06-06 11:52:18.192387 [INFO] [178.20.203.17:50997:HTTP2-19#depth.gallery] [REWRITE] Rule: Match 'favicon.ico' with pattern '(.+)\.(jpe?g|png)$', result: -1



I'm not sure what to make of this other than, yeah, it's not applying the .webp rewrite rule. Can anyone gather any info from this?
 
Top