PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 4.1.2
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v4.1.2
4.1.2 4.1.1 4.1.0 4.0.1 4.0.0 3.3.1 3.3.0 trunk 1.0.0 2.0.0 2.1.0 3.0.0 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8
← All changes | admin/rewrite-rules/class-iis.php +51 -32 3.3.14.1.2 View file →
@@ -1,10 +1,11 @@
1 1 <?php
2 +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2 3
3 4 include_once QUICKWEBP_PLUGIN_PATH . 'admin/rewrite-rules/class-rewrite-rules-abstract.php';
4 5
5 6
6 -class IIS extends Rewrite_Rules_Abstract {
7 +class Quickwebp_IIS extends Quickwebp_Rewrite_Rules_Abstract {
7 8
8 9 /**
9 10 * Get the path to the file.
10 11 */
@@ -21,38 +22,56 @@
21 22 $extensions = 'jpg|jpeg|jpe|png';
22 23 $home_root = wp_parse_url( home_url( '/' ) );
23 24 $home_root = $home_root['path'];
24 25
25 - return trim( '
26 -# BEGIN ' . $this->tag_name . '
27 -<!-- @parent /configuration/system.webServer/rewrite/rules -->
28 -<rule name="' . esc_attr( $this->tag_name ) . ' 2">
29 - <match url="^(' . $home_root . '.+)\.(' . $extensions . ')$" ignoreCase="true" />
30 - <conditions logicalGrouping="MatchAll">
31 - <add input="{HTTP_ACCEPT}" pattern="image/webp" ignoreCase="false" />
32 - <add input="{DOCUMENT_ROOT}/{R:1}{R:2}.webp" matchType="IsFile" />
33 - </conditions>
34 - <action type="Rewrite" url="{R:1}{R:2}.webp" logRewrittenUrl="true" />
35 - <serverVariables>
36 - <set name="ACCEPTS_WEBP" value="true" />
37 - </serverVariables>
38 -</rule>
26 + $content = '# BEGIN ' . $this->tag_name . "\n";
27 + $content .= '<!-- @parent /configuration/system.webServer/rewrite/rules -->';
39 28
40 -<!-- @parent /configuration/system.webServer/rewrite/outboundRules -->
41 -<rule preCondition="IsWebp" name="' . esc_attr( $this->tag_name ) . ' 3">
42 - <match serverVariable="RESPONSE_Vary" pattern=".*" />
43 - <action type="Rewrite" value="Accept"/>
44 -</rule>
45 -<preConditions name="' . esc_attr( $this->tag_name ) . ' 4">
46 - <preCondition name="IsWebp">
47 - <add input="{ACCEPTS_WEBP}" pattern="true" ignoreCase="false" />
48 - </preCondition>
49 -</preConditions>
29 + // Serve AVIF first
30 + $content .= "\n<rule name=\"" . esc_attr( $this->tag_name ) . " AVIF\">";
31 + $content .= "\n\t<match url=\"^(" . $home_root . ".+)\\.(" . $extensions . ")$\" ignoreCase=\"true\" />";
32 + $content .= "\n\t<conditions logicalGrouping=\"MatchAll\">";
33 + $content .= "\n\t\t<add input=\"{HTTP_ACCEPT}\" pattern=\"image/avif\" ignoreCase=\"false\" />";
34 + $content .= "\n\t\t<add input=\"{DOCUMENT_ROOT}/{R:1}{R:2}.avif\" matchType=\"IsFile\" />";
35 + $content .= "\n\t</conditions>";
36 + $content .= "\n\t<action type=\"Rewrite\" url=\"{R:1}{R:2}.avif\" logRewrittenUrl=\"true\" />";
37 + $content .= "\n\t<serverVariables>";
38 + $content .= "\n\t\t<set name=\"ACCEPTS_IMAGE\" value=\"true\" />";
39 + $content .= "\n\t</serverVariables>";
40 + $content .= "\n</rule>";
50 41
51 -<!-- @parent /configuration/system.webServer -->
52 -<staticContent name="' . esc_attr( $this->tag_name ) . ' 1">
53 - <mimeMap fileExtension=".webp" mimeType="image/webp" />
54 -</staticContent>
55 -# END ' . $this->tag_name . '');
42 + // Serve WebP if AVIF isn't available
43 + $content .= "\n\n<rule name=\"" . esc_attr( $this->tag_name ) . " WebP\">";
44 + $content .= "\n\t<match url=\"^(" . $home_root . ".+)\\.(" . $extensions . ")$\" ignoreCase=\"true\" />";
45 + $content .= "\n\t<conditions logicalGrouping=\"MatchAll\">";
46 + $content .= "\n\t\t<add input=\"{HTTP_ACCEPT}\" pattern=\"image/webp\" ignoreCase=\"false\" />";
47 + $content .= "\n\t\t<add input=\"{DOCUMENT_ROOT}/{R:1}{R:2}.webp\" matchType=\"IsFile\" />";
48 + $content .= "\n\t</conditions>";
49 + $content .= "\n\t<action type=\"Rewrite\" url=\"{R:1}{R:2}.webp\" logRewrittenUrl=\"true\" />";
50 + $content .= "\n\t<serverVariables>";
51 + $content .= "\n\t\t<set name=\"ACCEPTS_IMAGE\" value=\"true\" />";
52 + $content .= "\n\t</serverVariables>";
53 + $content .= "\n</rule>";
54 +
55 + $content .= "\n\n<!-- @parent /configuration/system.webServer/rewrite/outboundRules -->";
56 + $content .= "\n<rule preCondition=\"IsModernImage\" name=\"" . esc_attr( $this->tag_name ) . " Vary\">";
57 + $content .= "\n\t<match serverVariable=\"RESPONSE_Vary\" pattern=\".*\" />";
58 + $content .= "\n\t<action type=\"Rewrite\" value=\"Accept\" />";
59 + $content .= "\n</rule>";
60 +
61 + $content .= "\n<preConditions name=\"" . esc_attr( $this->tag_name ) . " Preconditions\">";
62 + $content .= "\n\t<preCondition name=\"IsModernImage\">";
63 + $content .= "\n\t\t<add input=\"{ACCEPTS_IMAGE}\" pattern=\"true\" ignoreCase=\"false\" />";
64 + $content .= "\n\t</preCondition>";
65 + $content .= "\n</preConditions>";
66 +
67 + $content .= "\n\n<!-- @parent /configuration/system.webServer -->";
68 + $content .= "\n<staticContent name=\"" . esc_attr( $this->tag_name ) . " Mime\">";
69 + $content .= "\n\t<mimeMap fileExtension=\".webp\" mimeType=\"image/webp\" />";
70 + $content .= "\n\t<mimeMap fileExtension=\".avif\" mimeType=\"image/avif\" />";
71 + $content .= "\n</staticContent>";
72 +
73 + $content .= "\n# END " . $this->tag_name;
74 +
75 + return trim( $content );
56 76 }
57 -
58 -}
77 +}