• Resolved joben

    (@joben)


    I am using IIS as the web server.
    I have added .webp as an allowed MIME type in IIS.
    I can see the converted files in the /wp-content/uploads-webpc/ folder.
    I can also see the images loading properly in the browser if I go to the image URL.

    However, the .webp versions of the images are not loading instead of the jpeg or png versions when visiting the website. We are not using mod_rewrite which I suspect is the reason why the image URLs are not being redirected.
    How do I find the rewrite rules? IIS has a mod_rewrite converter that places the rules in the web.config file that usually works quite well.

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

    (@mateuszgbiorczyk)

    Hi @joben ,

    Thank you for your message. I have to admit that we didn’t do tests on IIS.

    Are you able to get the rules from the .htaccess file and use them in the configuration?

    Thread Starter joben

    (@joben)

    Hi Mateusz and thanks for the reply!

    I actually never found that any .htaccess file was created, but I found an existing IIS URL Rewrite rule on some random website that I modified slightly, and it actually worked as intended after I generated the webp files. It served me webp files in Chrome and regular files in Edge.

    However, a few of the png images and jpg images didn’t get converted. I compared the original folder with the destination folder so I know that some of the webp images do not exist. I havn’t found any logs or debug messages from the generation process so I still don’t know what’s wrong.

    Here is the current IIS Rewrite rule that I am using:

    <rule name="Webp1" enabled="true" stopProcessing="true">
        <match url=".*wp-content/uploads.*/([0-9]*)/([0-9]*)/(.*_.*)(\.jpg|\.jpeg|\.png)" />
        <conditions logicalGrouping="MatchAny">
                            <add input="{HTTP_ACCEPT}" pattern="\bimage/webp\b" />
        </conditions>
        <action type="Rewrite" url="/wp-content/uploads-webpc/{R:1}/{R:2}/{R:3}{R:4}.webp" logRewrittenUrl="false" />
    </rule>
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Here you can find all the rules that occur in the .htaccess file:

    # BEGIN WebP Converter
    <IfModule mod_mime.c>
      AddType image/webp .webp
    </IfModule>
    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
      RewriteRule wp-content/uploads/(.+)\.jpg$ wp-content/uploads-webpc/$1.jpg.webp [T=image/webp]
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpeg.webp -f
      RewriteRule wp-content/uploads/(.+)\.jpeg$ wp-content/uploads-webpc/$1.jpeg.webp [T=image/webp]
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.png.webp -f
      RewriteRule wp-content/uploads/(.+)\.png$ wp-content/uploads-webpc/$1.png.webp [T=image/webp]
    </IfModule>
    <IfModule mod_expires.c>
      ExpiresActive On
      ExpiresByType image/webp "access plus 1 year"
    </IfModule>
    # END WebP Converter
    Thread Starter joben

    (@joben)

    I tried importing the rules in IIS but it failed because the T= flag is not recognized.
    I removed the T flags but the rules are not working properly.

    I think what is needed for this to work in IIS is one of these things:

    Option 1: Troubleshoot the converter why some images are not converted and use the rule that I posted.
    Option 2: Write an IIS rule that loads the webp image only if it exists, if it doesnt, load the original jpeg/png version.

    I lack the necessary skills to make it work, but if anyone wants me to test something or debug in an IIS environment I am happy to help.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Thank you for your help and time, I appreciate very much.

    T flag is required for this plugin to work. This is what its “magic” is all about, ie redirects to WebP files that do not change the URL.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘IIS compatibility?’ is closed to new replies.