1<IfModule mod_setenvif.c>
2 # Vary: Accept for all the requests to jpeg and png
3 SetEnvIf Request_URI "\.(jpe?g|png)$" REQUEST_image
4</IfModule>
5
6<IfModule mod_rewrite.c>
7 RewriteEngine On
8
9 # Check if browser supports WebP images
10 RewriteCond%{HTTP_ACCEPT}image/webp
11
12 # Check if WebP replacement image exists
13 RewriteCond%{DOCUMENT_ROOT}/$1.webp-f
14
15 # Serve WebP image instead
16 RewriteRule(.+)\.(jpe?g|png)$$1.webp[T=image/webp]
17</IfModule>
18
19<IfModule mod_headers.c>
20 Header append Vary Accept env=REQUEST_image
21</IfModule>
22
23<IfModule mod_mime.c>
24 AddType image/webp .webp
25</IfModule>