• Resolved zielinski

    (@zielinski)


    I installed this plugins and converted all JPG files in the upload folder. mod_rewrite works. Unfortunately the JPG files are served instead of the WEBP files.

    After digging in the code I commended out this line in .htaccess:
    RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f

    But what if a corresponding WEBP file doesn’t exist?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @zielinski,

    Thank you for your message.

    Your hosting probably sets another value as %{DOCUMENT_ROOT}. Check out this thread: https://www.ads-software.com/support/topic/webp-converter-does-not-work-at-all/

    Did this help you?

    Thread Starter zielinski

    (@zielinski)

    That is my walkaround:

    add_filter('webpc_htaccess_mod_rewrite', function($rules) {
      return '<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{HTTP_ACCEPT} image/webp
        RewriteCond ' . WP_CONTENT_DIR . '/uploads-webpc/$1.$2.webp -f
        RewriteRule (.+)\.(jpe?g|png)$ /wp-content/uploads-webpc/$1.$2.webp [NC,T=image/webp,E=cache-control:private,L]
      </IfModule>';
    });

    You can minimize you .htaccess by putting the extension to the second regex group.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    I’m glad you were able to solve the problem. Yes, you are right – at the moment it is divided, because the user can conveniently change the supported formats, but I will take this into account.

    @zielinski ‘s solution didn’t work for me.

    [EDIT] Turns out my actual problem was the webp files were larger than the originals so they were being deleted as per the setting in the plugin.
    When I turned my compression settings to 80% I started getting webp image substitutions as expected.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Possible issue with DOCUMENT_ROOT in .htaccess’ is closed to new replies.