Support » Plugin: EWWW Image Optimizer » The .htaccess code for webp is wrong

  • Resolved tschopo


    The .htaccess code has a logical error:

    # 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 mod_headers.c>
    Header append Vary Accept env=REDIRECT_accept
    AddType image/webp .webp

    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 mod_headers.c>
    Header set Expires "max-age=A10368000, public"
    Header unset ETag
    Header set Connection keep-alive
    FileETag None

    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
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author nosilver4u


    Thanks for reporting that, it’s been there so long, and I’d never dug into the “Header append” rule enough to realize that it was only setting the Vary header IF the redirect was successful. Indeed, it ought to append the header always, or at least for JPG/PNG/GIF images like you said.
    Not so sure about WebP, if the URL is for a WebP image, there shouldn’t be any “varying” going on, or am I missing something there?

    Thread Starter tschopo


    Yes that is correct, for webp URLs the Vary header does not have to be set.

    Plugin Author nosilver4u


    The updated rules will be included in the next release, thanks again!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘The .htaccess code for webp is wrong’ is closed to new replies.