PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 3.2.6
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v3.2.6
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
quickwebp / admin / rewrite-rules / class-apache.php

class-apache.php in QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress 3.2.6, at admin/rewrite-rules/class-apache.php

55 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 include_once QUICKWEBP_PLUGIN_PATH . 'admin/rewrite-rules/class-rewrite-rules-abstract.php';
4
5 class Apache extends Rewrite_Rules_Abstract {
6
7 /**
8 * Get the path to the file.
9 */
10 protected function get_file_path() {
11 $file_path = $this->get_site_root() . '.htaccess';
12
13 return $file_path;
14 }
15
16 /**
17 * Get unfiltered new contents to write into the file.
18 */
19 protected function get_raw_new_contents() {
20 $extensions = 'jpg|jpeg|jpe|png';
21 $home_root = wp_parse_url( home_url( '/' ) );
22 $home_root = $home_root['path'];
23
24 return trim( '
25 # BEGIN ' . $this->tag_name . '
26 <IfModule mod_setenvif.c>
27 # Vary: Accept for all the requests to jpeg and png.
28 SetEnvIf Request_URI "\.(' . $extensions . ')$" REQUEST_image
29 </IfModule>
30
31 <IfModule mod_rewrite.c>
32 RewriteEngine On
33 RewriteBase ' . $home_root . '
34
35 # Check if browser supports WebP images.
36 RewriteCond %{HTTP_ACCEPT} image/webp
37
38 # Check if WebP replacement image exists.
39 RewriteCond %{REQUEST_FILENAME}.webp -f
40
41 # Serve WebP image instead.
42 RewriteRule (.+)\.(' . $extensions . ')$ $1.$2.webp [T=image/webp,NC]
43 </IfModule>
44
45 <IfModule mod_headers.c>
46 Header append Vary Accept env=REQUEST_image
47 </IfModule>
48
49 <IfModule mod_mime.c>
50 AddType image/webp .webp
51 </IfModule>
52 # END ' . $this->tag_name .'' );
53 }
54
55 }