First post here, so I hope I did it well.
I converted all png/jpg starting from my prestashop public_html folder to webp, and added rewrite rules to the .htaccess in order to have the webp served instead of png/jpg.
I based my rewrites on the already existing prestashop rewrites.
Where I had:
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
I ended up doing:
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.webp [L]
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.webp [L]
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
Which works: I got jpg URL serving webp images, so far so good (I know still need to implement
#RewriteCond %{HTTP_ACCEPT} image/webp
#RewriteCond %{DOCUMENT_ROOT}/$1.webp -f
and as well try to figure out if I should leave [L]
or do [L,T=image/webp]
or do [T=image/webp,E=REQUEST_image]
, which is why I am reading apache related docs and crawling the web about rewrite related topics which is quiet huge indeed.
Ok, so back to the main topic, I saw that I was missing a webp rewrite for the images the prestashop stores in public_html/img folder.
Then I tried the following (and so other variants):
RewriteRule ^/img/(.+)\.jpe?g$ /img/$1.webp [L]
RewriteRule ^/img/(.+)\.png$ /img/$1.webp [L]
^--- NOT OK... still serving jpg/png type images from the img directory (double checked the MIME Type).
Note that:
- Every time I changed .htaccess and tried a solution, I cleared the prestashop cache, just in case (despite knowing the .htaccess being read at every request).
- webp images corresponding to jpg/png in img folder exist.
- image file perms is correct in img folder and indeed in all stuff under public_html
- In img folder in prestashop, there is another .htaccess, which restricts the type of files that can be served from this folder, and I added already webp, just in case someone should ask.
UPDATE: As requested by MrWhite, adding the .htaccess of the img folder
<IfModule mod_php5.c>
php_flag engine off
</IfModule>
# Apache 2.2
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
<Files ~ "(?i)^.*\.(webp|jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico)$">
Allow from all
</Files>
</IfModule>
# Apache 2.4
<IfModule mod_authz_core.c>
Require all denied
<Files ~ "(?i)^.*\.(webp|jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico)$">
Require all granted
</Files>
</IfModule>
Please could you guys kindly help me here?