PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.7.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.7.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / views / cache / htaccess.php

htaccess.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.7.0, at src/views/cache/htaccess.php

98 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The template used to generate our htaccess configuration.
4 *
5 * Start and End tags are added with the modifier.
6 *
7 * @see \SolidWP\Performance\Cache_Delivery\Htaccess\Modifier
8 *
9 * @var string $base The RewriteBase to use.
10 * @var string $cache_path The relative path from WP_CONTENT_DIR without slashes, e.g. wp-content/cache/solid-performance/page
11 * @var string $site_cache_path The absolute path to the cache files, .e.g /app/wp-content/cache/solid-performance/page/$host
12 * @var string $extensions_regex The FilesMatch extensions regex for our cache files, e.g. html|gz.
13 *
14 * @package SolidWP\Performance
15 */
16
17 declare( strict_types=1 );
18
19 $htaccess = <<<RULES
20 <IfModule mod_expires.c>
21 ExpiresActive on
22 ExpiresByType text/html "access plus 0 seconds"
23 </IfModule>
24
25 <IfModule mod_headers.c>
26 Header set Referrer-Policy "no-referrer-when-downgrade"
27 </IfModule>
28
29 # Avoid recompressing already compressed files
30 <IfModule mod_setenvif.c>
31 SetEnvIfNoCase Request_URI \.gz$ no-gzip
32 </IfModule>
33
34 <IfModule mod_rewrite.c>
35 RewriteEngine On
36 RewriteBase $base
37
38 RewriteRule .* - [E=SWPSP_SCHEME:-http]
39 RewriteRule .* - [E=SWPSP_EXT:html]
40
41 RewriteCond %{HTTPS} on [OR]
42 RewriteCond %{SERVER_PORT} ^443$ [OR]
43 RewriteCond %{HTTP:X-Forwarded-Proto} https
44 RewriteRule .* - [E=SWPSP_SCHEME:-https]
45
46 <IfModule mod_deflate.c>
47 <IfModule mod_mime.c>
48 AddType text/html .gz
49 AddEncoding gzip .gz
50 </IfModule>
51
52 <IfModule mod_filter.c>
53 AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon application/json application/vnd.ms-access video/webm application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.presentation application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf application/vnd.ms-opentype audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel
54
55 <IfModule mod_mime.c>
56 # DEFLATE by extension
57 AddOutputFilter DEFLATE js css htm html xml
58 </IfModule>
59 </IfModule>
60
61 RewriteCond %{HTTP:Accept-Encoding} gzip
62 RewriteRule .* - [E=SWPSP_EXT:gz]
63 </IfModule>
64
65 # Fallback if the extension is gz but a gz file was never created, check for a .html extension
66 RewriteCond %{ENV:SWPSP_EXT} =gz
67 RewriteCond "%{DOCUMENT_ROOT}$base$cache_path/%{HTTP_HOST}/%{REQUEST_URI}/index%{ENV:SWPSP_SCHEME}.gz" !-f
68 RewriteCond "$site_cache_path/%{REQUEST_URI}/index%{ENV:SWPSP_SCHEME}.gz" !-f
69 RewriteRule .* - [E=SWPSP_EXT:html]
70
71 RewriteCond %{REQUEST_METHOD} GET
72 RewriteCond %{QUERY_STRING} ^$
73 RewriteCond %{REQUEST_FILENAME} !-f
74 RewriteCond %{HTTP:Cookie} !(wordpress_logged_in_.+|wp-postpass_|wptouch_switch_toggle|comment_author_|comment_author_email_) [NC]
75 RewriteCond %{REQUEST_URI} !^(/(?:.+/)?feed(?:/(?:.+/?)?)?$|/(?:.+/)?embed/|/(index.php/)?(.*)wp-json(/.*|$))$ [NC]
76 RewriteCond "%{DOCUMENT_ROOT}$base$cache_path/%{HTTP_HOST}/%{REQUEST_URI}/index%{ENV:SWPSP_SCHEME}.%{ENV:SWPSP_EXT}" -f [OR]
77 RewriteCond "$site_cache_path/%{REQUEST_URI}/index%{ENV:SWPSP_SCHEME}.%{ENV:SWPSP_EXT}" -f
78 RewriteRule .* "$base$cache_path/%{HTTP_HOST}/%{REQUEST_URI}/index%{ENV:SWPSP_SCHEME}.%{ENV:SWPSP_EXT}" [L]
79 </IfModule>
80
81 # Detect if a cached file was served and set the proper headers
82 <IfModule mod_headers.c>
83 <FilesMatch "index-(https|http)\.($extensions_regex)$">
84 FileETag None
85 Header unset ETag
86 Header unset Pragma
87 Header append Cache-Control "public"
88 Header append Vary: Accept-Encoding
89 Header always set X-Cached-By "Solid Performance (htaccess)"
90 Header set X-Cache "HIT"
91 </FilesMatch>
92 </IfModule>
93
94 RULES;
95
96 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, StellarWP.XSS.EscapeOutput.OutputNotEscaped
97 echo apply_filters( 'solidwp/performance/htaccess/rules', $htaccess, $cache_path );
98