This plugin, [wordpress.org/plugins/webp-converter-for-media/](WebP Converter for Media) for Webp wordpress is very popular and needs some minor modifications to wpcommon for it to work. The current webp rules (see below) do not follow how the extension works--it converts and places webp photos in another directory. It also uses the original extension and then adds .webp (so image.jpg becomes image.jpg.webp)
Original wpcommon-php74:
webp rewrite rules for jpg and png images
try to load alternative image.png.webp before image.png
location /wp-content/uploads {
location ~ \.(png|jpe?g)$ {
add_header Vary "Accept-Encoding";
more_set_headers 'Access-Control-Allow-Origin : *';
more_set_headers "Cache-Control : public, no-transform";
access_log off;
log_not_found off;
expires max;
try_files $uri$webp_suffix $uri =404;
}
location ~* \.(php|gz|log|zip|tar|rar|xz)$ {
#Prevent Direct Access Of PHP Files & Backups from Web Browsers
deny all;
}
To make it work with the extension, I had to comment out the above line and add this into wpcommon:
#webp converter extension rewrite rules
location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif)$ {
if ($http_accept !~* "image/webp") {
break;
}
add_header Vary Accept;
add_header Cache-Control "private" always;
add_header Vary "Accept-Encoding";
more_set_headers 'Access-Control-Allow-Origin : *';
more_set_headers "Cache-Control : public, no-transform";
access_log off;
log_not_found off;
expires 365d;
try_files /wp-content/uploads-webpc/$path.$ext.webp $uri =404;
}
I'm trying to think of a more elegant way to do this so I can just add a include file instead of modifying wpcommon itself. Every method I tried wouldn't work as the wpcommon webp rules would take precedence. Hope this helps someone using the plugin and perhaps someone much more knowledgable can come up with a better solution