Hi @idefixx,
Thank you for your message.
I haven’t tested such a solution, but I will tell you a few things that may be useful to you:
- original images are stored in the /wp-content/uploads/ directory
- converted to WebP and to AVIF files are stored in the /wp-content/uploads-webpc/uploads/ directory
- the plugin creates rules in .htaccess file in the /wp-content/ directory
If you map the same directory structure and copy the rules from the .htaccess file it should work. If you have a different directory structure, you should change the rules in the .htaccess file accordingly.
Best,
Mateusz
Hi @mateuszgbiorczyk,
Thank you so much for a quick and clear answer. I appreciate it.
I will give it a try. 😉
Hi Mateusz,
I believe I’m little bit closer to the final solution. But my knowledge of rewrite rules is just basic (copy/paste – honestly). Could you spare a minute and help me with it, please?
Original image URL example:
https://example.com/wp-content/uploads/image.jpg
.htaccess rule:
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
RewriteRule (.+)\.jpg$ /wp-content/uploads-webpc/$1.jpg.webp [NC,T=image/webp,L]
Creates this URL:
https://example.com/wp-content/uploads-webpc/wp-content/uploads/image.jpg.webp
But it should be:
https://example.com/wp-content/uploads-webpc/uploads/image.jpg.webp
So, here’s just a slight problem with doubled /wp-content/ in destination URL?
BTW. I’ve used https://htaccess.madewithlove.com to test the htaccess rule above.
Ah, a complete path to the file must be used.
RewriteRule ^wp-content/uploads/(.*)$ /wp-content/uploads-webpc/uploads/$1.webp [NC,T=image/webp,L]
😉
@idefixx So everything works fine now?
@mateuszgbiorczyk Well, not yet, I’ve to check .htaccess file with my webhosting provider technical support. Webserver still delivers .jpg/.png files instead of .webp files.
Here is .htaccess rule which (should) redirects .jpg to .jpg.webp files:
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
RewriteRule ^wp-content/uploads/(.+)\.jpg$ /wp-content/uploads-webpc/uploads/$1.jpg.webp [NC,T=image/webp,L]
BTW. webhosting is still the same as for non-prod website where’s no problem with .webp images.
@idefixx The plugin does not change the URLs – they remain the same. Below I have attached the tutorial describing how to test the plugin:
https://mattplugins.com/docs/how-to-test-converter-for-media-plugin
Thank you, @mateuszgbiorczyk, for reminding me your tutorial how to test it. It’s really easy to get it working with Simply Static plugin (v. 3.0.9):
- Additional directory must be included in General settings > Include: [your webserver path]/wp-content/uploads-webpc/uploads/
- Copy .htaccess files from non-prod to prod from /wp-content/ and /uploads/
- Test it; e.g. via PageSpeed Insights – Serve images in next-gen formats
That’s it. 😉
P.S.: AVIF image format works too.
-
This reply was modified 2 years, 5 months ago by
IdeFixx.
@idefixx Thank you for the confirmation and for your tutorial!