(Help) Automatic png, jpg to webp conversion on wordpress

#1
Hello, I'm writing here after many searches and unsuccessful attempts to set up automatic conversion of jpg, png images to webp when the browser supports it on my wordpress.

I've converted my images to webp with the WebP Express extension, but I can't activate automatic conversion of images to webp (image.png.webp or image.jpg.webp).

I've tried using the rewrite rules in .htaccess but it doesn't work, I've also tried adding two static context for image rewriting but nothing either ((https://forum.openlitespeed.org/thr...t-still-execute-document-level-rewrites.5160/).

I'm using WP Rocket as my cache extension, so I can't use LiteSpeed Cache.
My server runs on OpenLiteSpeed 1.7.19 in multi-domain.

Thanks in advance for your help.
config-webp-express.png context-static-1.png context-static-2.png
 

Cold-Egg

Administrator
#2
Does it work if you visit the png and webp images directly from the browser? If so, a general rewriterule should work.

I'm not pretty sure how the WebP Express extension handles the serving webp to the browser, you might want to contact them with more information.
 
#3
Hello, thank you for your reply.

When you ask if it works directly from the browser, you say to add .webp to the extension in the url? If yes, then yes it works.

Webp Express can handle the conversion in several different ways, but they recommend it as configured. Then, they use redirection rules with .htaccess but I have the impression that these rules are ignored...

I just saw that I had another error message:

"It seems your server setup does not support headers in .htaccess. You should either fix this (install mod_headers) or deactivate the "Enable direct redirection to existing converted images?" option. Otherwise the Vary:Accept header will not be added and this can result in problems for users behind proxy servers (ie used in larger companies)"

And while looking for this error, I saw that OpenLiteSpeed doesn't support rewrite rules in .htaccess, do you have a solution?
 
Last edited:

LiteCache

Active Member
#5
@SeikoSEO

This is not a rewrite issue with OLS. Check the rewrite rules added by WebP Express. It redirects to a PHP file to convert jpg|png to webp, but if a page is cached there is no PHP.
 
#6
Hello, thank you for your answers.

@Cold-Egg
Yes, I've enabled rewriting and autoload of .htaccess.

If I've understood correctly, Vary:accept is used to check whether the user's browser supports the webp extension.

Here are the contents of the .htaccess file
https://pastebin.com/QDN2qtHm

@LiteCache
I've disabled redirection to convert the image, I've converted all the images beforehand.

Thank you in advance.
 
Last edited:
#7
Hello again,

well, I've just found the solution by chance^^.

Maybe it will help some of you:

I use WP Rocket as a cache extension and they have a "WebP Compatibility" option that was disabled. So I activated it and now I have WebP images.

It's really weird because WP Rocket advises against enabling this option if our WebP plugin is serving webp images (which is the case for me).
 
#8
You already have the most difficult part working: WebP Express is generating the .webp versions. The remaining problem is mainly how OpenLiteSpeed/WordPress serves those files automatically when the browser supports WebP.
Since you're using WP Rocket instead of LiteSpeed Cache, I would avoid adding LiteSpeed Cache-specific rules. First, make sure the generated .webp files are actually accessible directly. For example:
/wp-content/uploads/2026/10/example.jpg.webp
If the WebP file loads correctly when accessed directly, but WordPress still serves the original JPG/PNG, then the problem is most likely the rewrite or content-negotiation configuration rather than WebP generation itself.
Also check that the browser sends:
Accept: image/webp
You can test this using your browser's developer tools under the Network tab. Compare the response for the original image and the .webp version, especially the Content-Type and response URL.
If you don't need automatic server-side replacement and simply want to convert existing images, an online converter can be useful. For example, JPG to WebP converter and PNG to WebP converter can convert the files directly in the browser without installing another WordPress plugin.
This can be useful if you only need to convert a batch of existing JPG/PNG images. However, for your particular setup, I would still focus on fixing the OpenLiteSpeed rewrite first, because that will allow WordPress to serve the WebP versions automatically rather than requiring manual conversion for every image.
 
Top