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>
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.
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.