• Resolved dfnsk

    (@dfnsk)


    Hello! First of all, great plugin, thank you! Very easy to install. Works almost out of the box (at least on shared hosting).

    My question is can I make an exception and NOT convert images on specific post or just specific image? I understand that there is no settings for it, but I’m ok with the solution, where I shoud add some lines of code to .php files or make some changes to .htaccess?

    P. S. I’m making a post about art posters and for that kind of images webp is really contraindicated ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author rosell.dk

    (@roselldk)

    You could place something like this in wp-content/.htaccess, above the WebP Express rules to bypass webp redirections for all images in a folder:

    
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^uploads/2019/02 - [L]
    

    Or like this to bypass a specific files:

    
    RewriteRule ^uploads/2019/02/image1\.jpg - [L]
    RewriteRule ^uploads/2019/02/image2\.jpg - [L]
    
    • This reply was modified 5 years, 9 months ago by rosell.dk.
    • This reply was modified 5 years, 9 months ago by rosell.dk.
    Plugin Author rosell.dk

    (@roselldk)

    Getting a bit smarter, you can add the following before the WebP Express rules:

    
    RewriteCond %{QUERY_STRING} original
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule . - [L]
    

    This will pass through all requests that has the “original” in the querystring.
    So you can append “?original” the images which you want to bypass conversion.
    Ie img src=”wp-content/uploads/2019/02/image.jpg?original”

    • This reply was modified 5 years, 9 months ago by rosell.dk.
    • This reply was modified 5 years, 9 months ago by rosell.dk.
    • This reply was modified 5 years, 9 months ago by rosell.dk.
    • This reply was modified 5 years, 9 months ago by rosell.dk.
    Thread Starter dfnsk

    (@dfnsk)

    Thank you so much!!!

    Hello, could you give an example of the .htaccess file? I do everything according to your instructions, but exceptions do not work. Thank

    Mine is also not working, can you look at let me know if I am doing it right?

    I have added the exception code at the end of the JPG files I do not wish to convert in my Banners Folder.

    src=”/wp-content/uploads/2019/03/TomandBunny-SQ.jpg?original”

    This is what my .htaccess file looks like, is this correct?

    # BEGIN WebP Express
    # The rules below are a result of the WebP Express options, WordPress configuration and the following .htaccess capability tests:
    # – mod_header working?: could not be determined
    # – pass variable from .htaccess to script through header working?: no
    # – pass variable from .htaccess to script through environment variable working?: could not be determined

    RewriteCond %{QUERY_STRING} original
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule . – [L]

    <IfModule mod_rewrite.c>
    RewriteEngine On

    # Redirect to existing converted image in cache-dir (if browser supports webp)
    RewriteCond %{HTTP_ACCEPT} image/webp
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{DOCUMENT_ROOT}/wp-content/webp-express/webp-images/doc-root/wp-content/$1.$2.webp -f
    RewriteRule ^/?(.+)\.(jpe?g|png)$ /wp-content/webp-express/webp-images/doc-root/wp-content/$1.$2.webp [NC,T=image/webp,E=EXISTING:1,L]

    # Make sure that browsers which does not support webp also gets the Vary:Accept header
    # when requesting images that would be redirected to existing webp on browsers that does.
    <IfModule mod_setenvif.c>
    SetEnvIf Request_URI “\.(jpe?g|png)$” ADDVARY
    </IfModule>

    # WebP Realizer: Redirect non-existing webp images to webp-realizer.php, which will locate corresponding jpg/png, convert it, and deliver the webp (if possible)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/?(.+)\.(webp)$ /wp-content/plugins/webp-express/wod/webp-realizer.php?xdestination-rel=xwp-content/$1.$2&wp-content=wp-content [E=DESTINATIONREL:wp-content/$0,E=WPCONTENT:wp-content,NC,L]

    # Redirect images to webp-on-demand.php (if browser supports webp)
    RewriteCond %{HTTP_ACCEPT} image/webp
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{QUERY_STRING} (.*)
    RewriteRule ^/?(.+)\.(jpe?g|png)$ /wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource-rel=xwp-content/$1.$2&wp-content=wp-content&%1 [E=REQFN:%{REQUEST_FILENAME},E=WPCONTENT:wp-content,NC,L]

    <IfModule mod_headers.c>
    <IfModule mod_setenvif.c>
    # Apache appends “REDIRECT_” in front of the environment variables defined in mod_rewrite, but LiteSpeed does not.
    # So, the next lines are for Apache, in order to set environment variables without “REDIRECT_”
    SetEnvIf REDIRECT_EXISTING 1 EXISTING=1
    SetEnvIf REDIRECT_ADDVARY 1 ADDVARY=1

    # Set Vary:Accept header for the image types handled by WebP Express.
    # The purpose is to make proxies and CDNs aware that the response varies with the Accept header.
    Header append “Vary” “Accept” env=ADDVARY

    # Set X-WebP-Express header for diagnose purposes
    Header set “X-WebP-Express” “Redirected directly to existing webp” env=EXISTING
    </IfModule>
    </IfModule>

    </IfModule>
    <IfModule mod_mime.c>
    AddType image/webp .webp
    </IfModule>

    # END WebP Express

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Can I make an exception for specific post/image?’ is closed to new replies.