The .htaccess code for webp is wrong
-
The .htaccess code has a logical error:
# BEGIN EWWWIO # Die Anweisungen (Zeilen) zwischen ?BEGIN EWWWIO“ und ?END EWWWIO“ sind # dynamisch generiert und sollten nur über WordPress-Filter ge?ndert werden. # Alle ?nderungen an den Anweisungen zwischen diesen Markierungen werden überschrieben. <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_ACCEPT} image/webp RewriteCond %{REQUEST_FILENAME} (.*)\.(jpe?g|png|gif)$ RewriteCond %{REQUEST_FILENAME}.webp -f RewriteCond %{QUERY_STRING} !type=original RewriteRule (.+)\.(jpe?g|png|gif)$ %{REQUEST_URI}.webp [T=image/webp,E=accept:1,L] </IfModule> <IfModule mod_headers.c> Header append Vary Accept env=REDIRECT_accept </IfModule> AddType image/webp .webp # END EWWWIO
This means the Vary header is only set when the Client sends HTTP_ACCEPT image/webp.
But the Vary header should also be sent if the client does not accept image/webp because if not, the caching system will store png/jpg in the cache and overwrite the webp version even for the clients that have webp enabled…
Testsetup (Server with nginx Cache)
Serve Cached images with:
<FilesMatch "\.(jpg|jpeg|png|gif|webp)(\.gz)?$"> <IfModule mod_expires.c> ExpiresActive On ExpiresDefault A0 ExpiresByType image/webp A10368000 ExpiresByType image/gif A10368000 ExpiresByType image/png A10368000 ExpiresByType image/jpg A10368000 ExpiresByType image/jpeg A10368000 </IfModule> <IfModule mod_headers.c> Header set Expires "max-age=A10368000, public" Header unset ETag Header set Connection keep-alive FileETag None </IfModule> </FilesMatch>
Step 1. Call website: Webp images are served
Step 2. Deactivate webp in Firefox (about:config, image.http.accept to “*/*”) and reload wesite: Webp images are not served (as expected)
Step 3. Reactivate webp in Firefox (about:config, image.http.accept to “image/webp,*/*”) and reload website: webp images are still not served
The Vary header should be sent for all images, not only when the client accepts webp:
<IfModule mod_headers.c> <FilesMatch "\.(jpe?g|png|webp|gif)$"> Header append Vary Accept </FilesMatch> </IfModule>
- The topic ‘The .htaccess code for webp is wrong’ is closed to new replies.