How to fix Cloudflare Polish on Apache web server

So if you have the same issue I was facing on multiple websites with WordPress and various caching plugins, the Polish feature from Cloudflare wasn’t converting any image to the WebP version.

After talking with the support (and investigating with Dr. Flare Chrome extension) I got the answer that the various requests had vary_header_present header in our origin web server.
In their documentation they explain that images can have only one single value for the Vary header that is accept-encoding.

So as I don’t know what is happening and reading the htaccess I didn’t found anything I said well, it’s time for a new rule that fix the issue just for the image files.
We want that other headers are applied for URLs, as example, so with a match we can achieve what we need.

<FilesMatch "\.(jpg|jpeg|png)$">
    <ifModule mod_headers.c>
    Header unset Vary
    Header set Vary "Accept-Encoding"

This htaccess rule will fix the issue, remember to purge the cache on Cloudflare.

Liked it? Take a second to support Mte90 on Patreon!
Become a patron at Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *