PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.2
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.2
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / classes / Webp / RewriteRules / IIS.php

IIS.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.2, at classes/Webp/RewriteRules/IIS.php

63 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare(strict_types=1);
3
4 namespace Imagify\Webp\RewriteRules;
5
6 use Imagify\WriteFile\AbstractIISDirConfFile;
7
8 /**
9 * Add and remove rewrite rules to the web.config file to display WebP images on the site.
10 *
11 * @since 1.9
12 */
13 class IIS extends AbstractIISDirConfFile {
14
15 /**
16 * Name of the tag used as block delemiter.
17 *
18 * @var string
19 * @since 1.9
20 */
21 const TAG_NAME = 'Imagify: rewrite rules for webp';
22
23 /**
24 * Get unfiltered new contents to write into the file.
25 *
26 * @since 1.9
27 * @source https://github.com/igrigorik/webp-detect/blob/master/iis.config
28 *
29 * @return string
30 */
31 protected function get_raw_new_contents() {
32 $extensions = $this->get_extensions_pattern();
33 $extensions = str_replace( '|webp', '', $extensions );
34 $home_root = wp_parse_url( home_url( '/' ) );
35 $home_root = $home_root['path'];
36
37 return trim( '
38 <!-- @parent /configuration/system.webServer/rewrite/rules -->
39 <rule name="' . esc_attr( static::TAG_NAME ) . ' 2">
40 <match url="^(' . $home_root . '.+)\.(' . $extensions . ')$" ignoreCase="true" />
41 <conditions logicalGrouping="MatchAll">
42 <add input="{HTTP_ACCEPT}" pattern="image/webp" ignoreCase="false" />
43 <add input="{DOCUMENT_ROOT}/{R:1}{R:2}.webp" matchType="IsFile" />
44 </conditions>
45 <action type="Rewrite" url="{R:1}{R:2}.webp" logRewrittenUrl="true" />
46 <serverVariables>
47 <set name="ACCEPTS_WEBP" value="true" />
48 </serverVariables>
49 </rule>
50
51 <!-- @parent /configuration/system.webServer/rewrite/outboundRules -->
52 <rule preCondition="IsWebp" name="' . esc_attr( static::TAG_NAME ) . ' 3">
53 <match serverVariable="RESPONSE_Vary" pattern=".*" />
54 <action type="Rewrite" value="Accept"/>
55 </rule>
56 <preConditions name="' . esc_attr( static::TAG_NAME ) . ' 4">
57 <preCondition name="IsWebp">
58 <add input="{ACCEPTS_WEBP}" pattern="true" ignoreCase="false" />
59 </preCondition>
60 </preConditions>' );
61 }
62 }
63