I use this code in .htaccess to serve webp file instead of .jpg and .png file when its supported by browser and webp file is available :
RewriteEngine on
<Files *.webp>
Header set Vary "Accept-Encoding"
AddType "image/webp" .webp
AddEncoding webp .webp
</Files>
RewriteCond %{HTTP:Accept} image/webp
RewriteCond %{REQUEST_FILENAME}.webp -f
RewriteRule ^(.*)$ $1.webp [L]
Usually it’s work great but in prestashop 1.7 there is a lot of rewrite for images, to make url seo friendly, so my rewrite is ignored :
RewriteRule ^([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
Rewrite.....
I’m stuck here, I can’t touch the prestashop rewrite because it’s fully generated, I just can add rules at the end of the htaccess file. Do you have any idea ?
2
Answers
I tried https://addons.prestashop.com/fr/visuels-produits/27669-image-webp-compression-regeneration.html works very well and a lot of usefull tools but will not convert every images easily
I finally use cloudflare with polish, wich manage all optimisations, webp included, in one click
I’m working on exactly the same problem at the moment.
I have a partial solution I can give, but it’s a bit more complicated than just modifying the htaccess.
I overide the Link.php, to have my image urls in img.jpg.webp format
I then wrote at the top of the htaccess this set of rules
You can use the hook actionHtaccessCreate in a module to write it automatically
The problem is that it does not handle the case where the corresponding webp image does not exist.
I continue my research on this rewriting of the htaccess.