Delivering WEBP images via HTACCESS

I'll start by stating what everybody else is saying: due to the huge variety of possible server configurations out there, using .HTACCESS to deliver the WEBP versions of the JPG files seamlessly (without altering the page code), while being a seductive idea, is actually the least recommended one. Everybody recommends moving the IMG tags inside PICTURE tags.
Important: this option won't work with websites using a CDN, Cloudflare in particular. This also won't work with solutions like Varnish

That being said, here are some pointers to take home about this issue:

  • The current .htaccess code block we're inserting in your .htaccess file represents the version we found to be most successful at accomplishing this task. We have sites it works on, sites it doesn't work on, the results vary, as expected.
  • Should you find a better version, you are free to use a file manager and edit the block of code yourself (you should absolutedly KNOW WHAT YOU'RE DOING there, otherwise you risk disabling your site). Hey, if you find something better, drop us a line too!
  • We included a very simple test in the SHORTPIXEL Advanced Settings tab, right under the "Without altering the page code (via .htaccess)" option, where you can see if your particular server CAN or CAN'T accomplish this (in other words, if our best effort code version really works out for you or not). While not fixing any issues in itself, this simple test can at least let you  know on the spot if the WEBP images will or will not be loaded in your pages when server via .htaccess. This way you can take an easier and faster decision on what option to use.

Still need help? Contact Us Contact Us