Delivering WebP images via .htaccess

Delivering WebP images via .htaccess is something you can do with ShortPixel Image Optimizer. You just need to activate the option "Without altering the page code (via .htaccess)" located on Settings > ShortPixel > Advanced > WebP Images > Deliver the WebP versions of the images in the front-end.

However, due to the huge variety of possible server configurations out there, using the .htaccess file to deliver the WebP versions of your JPG files seamlessly (without altering the page code), has some caveats you should be aware of.

  • The current 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 and 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 absolutely know what you're doing there, otherwise you risk breaking your site). Hey, if you find something better, drop us a line too!
  • We included a very simple test in the Advanced settings of our plugin, 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 served via .htaccess. This way you can take an easier and faster decision on what option to use.
  • This option does not work with websites using a CDN, Cloudflare in particular. 
  • This option also won't work with solutions like Varnish.

If you cannot use this method for any reasons, then you should try an alternative solution for serving WebP images like:

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us