-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses_Htaccess.php.html
More file actions
645 lines (561 loc) · 33 KB
/
classes_Htaccess.php.html
File metadata and controls
645 lines (561 loc) · 33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PoweredCache Hooks: Source: classes/Htaccess.php</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: classes/Htaccess.php</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code><?php
/**
* Htaccress rules
*
* @package PoweredCache
*/
namespace PoweredCache;
use function PoweredCache\Utils\get_cache_dir;
use function PoweredCache\Utils\mobile_browsers;
use function PoweredCache\Utils\mobile_prefixes;
use function PoweredCache\Utils\permalink_structure_has_trailingslash;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// phpcs:disable Generic.Strings.UnnecessaryStringConcat.Found
/**
* Class Htaccess
*/
class Htaccess {
/**
* Plugin settings
*
* @var $settings
*/
private $settings;
/**
* placeholder
*
* @since 2.5
*/
public function __construct() {
$this->settings = \PoweredCache\Utils\get_settings();
}
/**
* Return an instance of the current class
*
* @return Htaccess
*/
public static function factory() {
static $instance = false;
if ( ! $instance ) {
$instance = new self();
}
return $instance;
}
/**
* Get htaccess rules
*
* @return string
*/
public function htaccess_rules() {
$rules = '';
/**
* Filters base htaccess rules
*
* @hook powered_cache_pre_htaccess
*
* @param {string} empty htaccesss rules by default
*
* @return {boolean} New value.
*
* @since 1.1
*/
$rules .= apply_filters( 'powered_cache_pre_htaccess', '' );
$rules .= '# BEGIN POWERED CACHE' . PHP_EOL;
$rules .= $this->browser_cache_rules();
$rules .= $this->cors_rules();
$rules .= $this->gzip_rules();
$rules .= $this->etag_rules();
$rules .= $this->cache_control_rules();
$rules .= $this->file_optimizer_rewrite_rules();
$rules .= $this->rewrite_rules();
/**
* Filters post htaccess rules
*
* @hook powered_cache_after_htaccess
*
* @param {string} empty htaccesss rules by default
*
* @return {boolean} New value.
*
* @since 2.0
*/
$rules .= apply_filters( 'powered_cache_after_htaccess', '' );
$rules .= '# END POWERED CACHE' . PHP_EOL;
return $rules;
}
/**
* Browser cache rules
*
* @return string
*/
public function browser_cache_rules() {
$rules = '';
/**
* Filters whether doing the configuration for browser cache or not
*
* @hook powered_cache_browser_cache
*
* @param {boolean} true for creating .htaccess rules for browser cache
*
* @return {boolean} New value.
*
* @since 1.1
*/
if ( apply_filters( 'powered_cache_browser_cache', true ) ) {
$mime_types = [
'text/css',
'application/javascript',
'image/jpeg',
'image/gif',
'image/png',
'image/bmp',
'image/tiff',
'image/webp',
'image/heic',
'image/svg+xml',
'font/ttf',
'font/woff',
'font/woff2',
'font/otf',
'application/vnd.ms-fontobject',
'image/x-icon',
'application/atom+xml',
'application/rss+xml',
];
// set expire time
$rules .= '<IfModule mod_expires.c>' . PHP_EOL;
$rules .= ' ExpiresActive On' . PHP_EOL;
$rules .= ' ExpiresByType text/html "access plus 0 seconds"' . PHP_EOL;
$rules .= ' ExpiresByType text/richtext "access plus 0 seconds"' . PHP_EOL;
$rules .= ' ExpiresByType text/plain "access plus 0 seconds"' . PHP_EOL;
$rules .= ' ExpiresByType text/xsd "access plus 0 seconds"' . PHP_EOL;
$rules .= ' ExpiresByType text/xsl "access plus 0 seconds"' . PHP_EOL;
$rules .= ' ExpiresByType text/xml "access plus 0 seconds"' . PHP_EOL;
$rules .= ' ExpiresByType application/xml "access plus 0 seconds"' . PHP_EOL;
$rules .= ' ExpiresByType application/json "access plus 0 seconds"' . PHP_EOL;
$rules .= ' ExpiresByType text/cache-manifest "access plus 0 seconds"' . PHP_EOL;
foreach ( $mime_types as $mime_type ) {
$rules .= sprintf( ' ExpiresByType %s "%s"', str_pad( $mime_type, 30, ' ' ), $this->get_browser_cache_lifespan( $mime_type ) ) . PHP_EOL;
}
$rules .= '</IfModule>' . PHP_EOL;
}
return $rules;
}
/**
* Cors rules - when CDN integration activated
*
* @return string
*/
public function cors_rules() {
$rules = '';
/**
* Filters whether add CORS configuration or not
*
* @hook powered_cache_htaccess_add_cors
*
* @param {boolean} true for creating .htaccess rules for CORS
*
* @return {boolean} New value.
*
* @since 2.5
*/
if ( apply_filters( 'powered_cache_htaccess_add_cors', $this->settings['enable_cdn'] ) ) {
/**
* Add CORS configuration
*
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
* @since 2.1
*/
$rules .= '<IfModule mod_setenvif.c>' . PHP_EOL;
$rules .= ' <IfModule mod_headers.c>' . PHP_EOL;
$rules .= ' <FilesMatch "\.(avifs?|bmp|cur|gif|ico|jpe?g|jxl|a?png|svgz?|webp)$">' . PHP_EOL;
$rules .= ' SetEnvIf Origin ":" IS_CORS' . PHP_EOL;
$rules .= ' Header set Access-Control-Allow-Origin "*" env=IS_CORS' . PHP_EOL;
$rules .= ' </FilesMatch>' . PHP_EOL;
$rules .= ' </IfModule>' . PHP_EOL;
$rules .= '</IfModule>' . PHP_EOL . PHP_EOL;
// configure fonts
$rules .= '<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css)$">' . PHP_EOL;
$rules .= ' <IfModule mod_headers.c>' . PHP_EOL;
$rules .= ' Header set Access-Control-Allow-Origin "*"' . PHP_EOL;
$rules .= ' </IfModule>' . PHP_EOL;
$rules .= '</FilesMatch>' . PHP_EOL . PHP_EOL;
}
return $rules;
}
/**
* Gzip rules
*
* @return string
*/
public function gzip_rules() {
$rules = '';
$rules .= '<IfModule filter_module>' . PHP_EOL;
$rules .= ' <IfModule version.c>' . PHP_EOL;
$rules .= ' <IfVersion >= 2.4>' . PHP_EOL;
$rules .= ' FilterDeclare COMPRESS' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'application/atom+xml\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'application/javascript\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'application/json\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'application/ld+json\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'application/manifest+json\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'application/rss+xml\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'application/vnd.ms-fontobject\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'application/xhtml+xml\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'application/xml\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'font/opentype\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'image/svg+xml\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'image/x-icon\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'text/html\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'text/plain\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'text/x-component\'"' . PHP_EOL;
$rules .= ' FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} = \'text/xml\'"' . PHP_EOL;
$rules .= ' FilterChain COMPRESS' . PHP_EOL;
$rules .= ' FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no' . PHP_EOL;
$rules .= ' </IfVersion>' . PHP_EOL;
$rules .= ' </IfModule>' . PHP_EOL;
$rules .= '</IfModule>' . PHP_EOL;
$rules .= '<IfModule mod_deflate.c>' . PHP_EOL;
$rules .= ' SetOutputFilter DEFLATE' . PHP_EOL;
$rules .= ' <IfModule mod_setenvif.c>' . PHP_EOL;
$rules .= ' <IfModule mod_headers.c>' . PHP_EOL;
$rules .= ' SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding' . PHP_EOL;
$rules .= ' RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding' . PHP_EOL;
$rules .= ' </IfModule>' . PHP_EOL;
$rules .= ' </IfModule>' . PHP_EOL;
$rules .= ' <IfModule mod_filter.c>' . PHP_EOL;
$rules .= ' AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/ld+json \
application/manifest+json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/html \
text/plain \
text/css \
text/x-component \
text/xml' . PHP_EOL;
$rules .= ' </IfModule>' . PHP_EOL;
$rules .= ' <IfModule mod_headers.c>' . PHP_EOL;
$rules .= ' Header append Vary: Accept-Encoding' . PHP_EOL;
$rules .= ' </IfModule>' . PHP_EOL;
$rules .= '</IfModule>' . PHP_EOL . PHP_EOL;
return $rules;
}
/**
* Remove ETag rules
*
* @link https://htaccessbook.com/disable-etags/
* @return string
*/
public function etag_rules() {
// remove etag
$rules = '# Remove ETag' . PHP_EOL;
$rules = '<IfModule mod_headers.c>' . PHP_EOL;
$rules .= 'Header unset ETag' . PHP_EOL;
$rules .= '</IfModule>' . PHP_EOL;
$rules .= 'FileETag None' . PHP_EOL . PHP_EOL;
return $rules;
}
/**
* Rewrite rules
*
* @return string
*/
public function rewrite_rules() {
$rules = '';
/**
* Filters whether doing the configuration for htaccess rewrite cache or not
*
* @hook powered_cache_mod_rewrite
*
* @param {boolean} true for creating .htaccess rewrite rules.
*
* @return {boolean} New value.
*
* @since 2.0
*/
if ( apply_filters( 'powered_cache_mod_rewrite', true ) ) { // rewrite
// add gzip type for .html.gz format
if ( $this->is_gzip_enabled() ) {
$rules .= '<IfModule mod_mime.c>' . PHP_EOL;
$rules .= ' AddType text/html .html.gz' . PHP_EOL;
$rules .= ' AddEncoding gzip .gz' . PHP_EOL;
$rules .= '</IfModule>' . PHP_EOL;
$rules .= '<IfModule mod_setenvif.c>' . PHP_EOL;
$rules .= ' SetEnvIfNoCase Request_URI \.html.gz$ no-gzip' . PHP_EOL;
$rules .= '</IfModule>' . PHP_EOL;
}
$env_powered_cache_ua = '';
$env_powered_cache_ssl = '';
$env_powered_cache_enc = '';
$rewrite_base = wp_parse_url( home_url() );
$rewrite_base = isset( $rewrite_base['path'] ) ? trailingslashit( $rewrite_base['path'] ) : '/';
$rules .= '<IfModule mod_rewrite.c>' . PHP_EOL;
$rules .= ' RewriteEngine On' . PHP_EOL;
$rules .= ' RewriteBase ' . $rewrite_base . PHP_EOL;
$rules .= ' AddDefaultCharset UTF-8 ' . PHP_EOL;
if ( true === $this->settings['cache_mobile'] && true === $this->settings['cache_mobile_separate_file'] ) {
$mobile_browsers = addcslashes( implode( '|', preg_split( '/[\s*,\s*]*,+[\s*,\s*]*/', mobile_browsers() ) ), ' ' );
$mobile_prefixes = addcslashes( implode( '|', preg_split( '/[\s*,\s*]*,+[\s*,\s*]*/', mobile_prefixes() ) ), ' ' );
// mobile env set
$rules .= ' RewriteCond %{HTTP_USER_AGENT} (' . $mobile_browsers . ') [NC]' . PHP_EOL;
$rules .= ' RewriteRule .* - [E=PC_UA:-mobile]' . PHP_EOL;
$rules .= ' RewriteCond %{HTTP_USER_AGENT} ^(' . $mobile_prefixes . ') [NC]' . PHP_EOL;
$rules .= ' RewriteRule .* - [E=PC_UA:-mobile]' . PHP_EOL;
$env_powered_cache_ua = '%{ENV:PC_UA}';
}
$rules .= ' RewriteCond %{HTTPS} on [OR]' . PHP_EOL;
$rules .= ' RewriteCond %{SERVER_PORT} ^443$ [OR]' . PHP_EOL;
$rules .= ' RewriteCond %{HTTP:X-Forwarded-Proto} https' . PHP_EOL;
$rules .= ' RewriteRule .* - [E=PC_SSL:-https]' . PHP_EOL;
$env_powered_cache_ssl = '%{ENV:PC_SSL}';
if ( $this->is_gzip_enabled() ) {
$rules .= ' RewriteCond %{HTTP:Accept-Encoding} gzip' . PHP_EOL;
$rules .= ' RewriteRule .* - [E=PC_ENC:.gz]' . PHP_EOL;
$env_powered_cache_enc = '%{ENV:PC_ENC}';
}
$rules .= ' RewriteCond %{REQUEST_METHOD} !=POST' . PHP_EOL;
$rules .= ' RewriteCond %{QUERY_STRING} =""' . PHP_EOL;
if ( permalink_structure_has_trailingslash() ) {
$rules .= ' RewriteCond %{REQUEST_URI} !^.*[^/]$' . PHP_EOL;
$rules .= ' RewriteCond %{REQUEST_URI} !^.*//.*$' . PHP_EOL;
}
// Get root base
$site_root = wp_parse_url( site_url() );
$site_root = isset( $site_root['path'] ) ? trailingslashit( $site_root['path'] ) : '';
// reject user agent
$rejected_user_agents = (array) AdvancedCache::get_rejected_user_agents();
if ( ! empty( $rejected_user_agents ) ) {
$rules .= ' RewriteCond %{HTTP_USER_AGENT} !^(' . implode( '|', $rejected_user_agents ) . ').* [NC]' . PHP_EOL;
}
// rejected cookies
$rejected_cookies = AdvancedCache::get_rejected_cookies();
if ( ! empty( $rejected_cookies ) ) {
$rules .= ' RewriteCond %{HTTP:Cookie} !(' . implode( '|', $rejected_cookies ) . ') [NC]' . PHP_EOL;
}
// dont cache fbexternal
$rules .= ' RewriteCond %{HTTP_USER_AGENT} !^(facebookexternalhit).* [NC]' . PHP_EOL;
$cache_location = get_cache_dir();
$cache_location = untrailingslashit( $cache_location ) . '/powered-cache/';
if ( strpos( ABSPATH, $cache_location ) === false ) {
$cache_path = str_replace( $_SERVER['DOCUMENT_ROOT'], '', $cache_location ); // phpcs:ignore
} else {
$cache_path = $site_root . str_replace( ABSPATH, '', $cache_location );
}
/**
* Filters whether running on 1and1_hosting or not
*
* @hook powered_cache_maybe_1and1_hosting
*
* @param {boolean} $status true if /kunden/homepage directory exists
*
* @return {boolean} New value.
*
* @since 1.1
*/
if ( apply_filters( 'powered_cache_maybe_1and1_hosting', ( 0 === strpos( $_SERVER['DOCUMENT_ROOT'], '/kunden/homepage/' ) ) ) ) { // phpcs:ignore
$rules .= ' RewriteCond "' . str_replace( '/kunden/homepage/', '/', $cache_location ) . '%{HTTP_HOST}' . '%{REQUEST_URI}/index' . $env_powered_cache_ssl . $env_powered_cache_ua . '.html' . $env_powered_cache_enc . '" -f' . PHP_EOL;
} else {
$rules .= ' RewriteCond "%{DOCUMENT_ROOT}/' . ltrim( $cache_path, '/' ) . '%{HTTP_HOST}' . '%{REQUEST_URI}/index' . $env_powered_cache_ssl . $env_powered_cache_ua . '.html' . $env_powered_cache_enc . '" -f' . PHP_EOL;
}
$rules .= ' RewriteRule .* "' . $cache_path . '%{HTTP_HOST}' . '%{REQUEST_URI}/index' . $env_powered_cache_ssl . $env_powered_cache_ua . '.html' . $env_powered_cache_enc . '" [L]' . PHP_EOL;
if ( $this->is_gzip_enabled() ) {
$rules .= ' # prevent mod_deflate double gzip' . PHP_EOL;
$rules .= ' RewriteRule \.html\.gz$ - [T=text/html,E=no-gzip:1]' . PHP_EOL;
}
$rules .= '</IfModule>' . PHP_EOL;
}
return $rules;
}
/**
* Apache allows both format like A2592000 => "access plus 1 month"
* A => access, M => Modified
*
* @param string $mime_type Mimetype
*
* @return string cache lifespan for apache
* @see http://httpd.apache.org/docs/current/mod/mod_expires.html
* @since 2.0
*/
public function get_browser_cache_lifespan( $mime_type ) {
switch ( $mime_type ) {
case 'text/css':
case 'application/javascript':
/**
* Filters TTL for CSS/JS files.
*
* @hook powered_cache_browser_cache_assets_lifespan
*
* @param {string} $expiry_time .htaccess lifespan
*
* @return {string} New value.
*
* @since 1.1
*/
$expiry_time = apply_filters( 'powered_cache_browser_cache_assets_lifespan', 'access plus 1 year' );
break;
case 'image/jpeg':
case 'image/gif':
case 'image/png':
case 'image/bmp':
case 'image/tiff':
case 'image/webp':
case 'image/heic':
$expiry_time = 'access plus 6 months';
break;
case 'image/x-icon':
$expiry_time = 'access plus 1 week'; // favicon
break;
case 'image/svg+xml':
case 'font/ttf':
case 'font/woff':
case 'font/woff2':
case 'font/otf':
case 'application/vnd.ms-fontobject':
$expiry_time = 'access plus 4 month';
break;
case 'application/atom+xml':
case 'application/rss+xml':
$expiry_time = 'access plus 1 hour';
break;
default:
/**
* Filters default TTL for browser cache lifespan.
*
* @hook powered_cache_browser_cache_default_lifespan
*
* @param {string} $expiry_time .htaccess lifespan
*
* @return {string} New value.
*
* @since 1.1
*/
$expiry_time = apply_filters( 'powered_cache_browser_cache_default_lifespan', 'access plus 1 month' );
}
/**
* Filters TTL for browser cache lifespan.
*
* @hook powered_cache_browser_cache_lifespan
*
* @param {string} $expiry_time .htaccess lifespan
* @param {string} $mime_type mime type
*
* @return {string} New value.
*
* @since 2.0
*/
$expiry_time = apply_filters( 'powered_cache_browser_cache_lifespan', $expiry_time, $mime_type );
return $expiry_time;
}
/**
* Check if the gzip option enabled
*
* @return bool
* @since 2.5
*/
public function is_gzip_enabled() {
/**
* Filters whether gzip enabled or not for the htaccess rules
*
* @hook powered_cache_htaccess_enable_gzip_compression
*
* @param {boolean} $status true if gzip option enabled on settings page
*
* @return {boolean} New value.
*
* @since 2.5
*/
return function_exists( 'gzencode' ) && apply_filters( 'powered_cache_htaccess_enable_gzip_compression', $this->settings['gzip_compression'] );
}
/**
* Cache-Control rules
*
* @return string
*/
public function cache_control_rules() {
$rules = '<FilesMatch "\.(html|htm|html\.gz|rtf|rtx|txt|xsd|xsl|xml)$">' . PHP_EOL;
$rules .= ' <IfModule mod_headers.c>' . PHP_EOL;
$rules .= ' Header set X-Powered-By "Powered Cache"' . PHP_EOL;
$rules .= ' Header unset Pragma' . PHP_EOL;
$rules .= ' Header append Cache-Control "public"' . PHP_EOL;
$rules .= ' </IfModule>' . PHP_EOL;
$rules .= '</FilesMatch>' . PHP_EOL;
/**
* Filters cache control rules
*
* @hook powered_cache_htaccess_cache_control_rules
*
* @param {string} $rules cache control
*
* @return {string} New value.
*
* @since 2.5
*/
$rules = apply_filters( 'powered_cache_htaccess_cache_control_rules', $rules );
return $rules;
}
/**
* Rewrite rules for file optimizer
*
* @return string|void
* @since 3.3
* https://example.com/wp-content/plugins/powered-cache/includes/file-optimizer.php??
* to
* https://example.com/_static/??
* @see https://docs.poweredcache.com/rewrite-file-optimizer/
*/
public function file_optimizer_rewrite_rules() {
if ( ! $this->settings['rewrite_file_optimizer'] ) {
return;
}
$file_optimizer_path = \PoweredCache\Optimizer\Helper::get_file_optimizer_relative_path();
$rules = '';
$rules .= '<IfModule mod_rewrite.c>' . PHP_EOL;
$rules .= ' # Enable rewrite engine' . PHP_EOL;
$rules .= ' RewriteEngine On' . PHP_EOL;
$rules .= ' # Redirect all requests starting with /_static/' . PHP_EOL;
$rules .= ' RewriteRule ^_static/.* ' . $file_optimizer_path . ' [L]' . PHP_EOL;
$rules .= '</IfModule>' . PHP_EOL;
return $rules;
}
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Actions</h3><ul><li><a href="powered_cache_admin_page_after_settings_nav.html">powered_cache_admin_page_after_settings_nav</a></li><li><a href="powered_cache_admin_page_before_file_optimization.html">powered_cache_admin_page_before_file_optimization</a></li><li><a href="powered_cache_advanced_cache_purge_on_comment_update.html">powered_cache_advanced_cache_purge_on_comment_update</a></li><li><a href="powered_cache_advanced_cache_purge_post.html">powered_cache_advanced_cache_purge_post</a></li><li><a href="powered_cache_after_clean_up.html">powered_cache_after_clean_up</a></li><li><a href="powered_cache_cache_dir_htaccess_file_content.html">powered_cache_cache_dir_htaccess_file_content</a></li><li><a href="powered_cache_cdn_setup.html">powered_cache_cdn_setup</a></li><li><a href="powered_cache_clean_site_cache_dir.html">powered_cache_clean_site_cache_dir</a></li><li><a href="powered_cache_create_config_file.html">powered_cache_create_config_file</a></li><li><a href="powered_cache_flushed.html">powered_cache_flushed</a></li><li><a href="powered_cache_fo_js_concat_did_items.html">powered_cache_fo_js_concat_did_items</a></li><li><a href="powered_cache_get_url_dir.html">powered_cache_get_url_dir</a></li><li><a href="powered_cache_init.html">powered_cache_init</a></li><li><a href="powered_cache_lazy_load_compat.html">powered_cache_lazy_load_compat</a></li><li><a href="powered_cache_lazy_load_filter.html">powered_cache_lazy_load_filter</a></li><li><a href="powered_cache_lazy_load_placeholder_url.html">powered_cache_lazy_load_placeholder_url</a></li><li><a href="powered_cache_loaded.html">powered_cache_loaded</a></li><li><a href="powered_cache_mobile_browsers.html">powered_cache_mobile_browsers</a></li><li><a href="powered_cache_mobile_prefixes.html">powered_cache_mobile_prefixes</a></li><li><a href="powered_cache_page_cache_enable.html">powered_cache_page_cache_enable</a></li><li><a href="powered_cache_page_cached.html">powered_cache_page_cached</a></li><li><a href="powered_cache_preload_http_request.html">powered_cache_preload_http_request</a></li><li><a href="powered_cache_purge_all_cache.html">powered_cache_purge_all_cache</a></li><li><a href="powered_cache_settings_saved.html">powered_cache_settings_saved</a></li><li><a href="powered_cache_updated.html">powered_cache_updated</a></li></ul><h3>Filters</h3><ul><li><a href="populate_preload_queue_urls.html">populate_preload_queue_urls</a></li><li><a href="powered_cache_accepted_query_strings.html">powered_cache_accepted_query_strings</a></li><li><a href="powered_cache_advanced_cache_file_content.html">powered_cache_advanced_cache_file_content</a></li><li><a href="powered_cache_advanced_cache_purge_urls.html">powered_cache_advanced_cache_purge_urls</a></li><li><a href="powered_cache_after_htaccess.html">powered_cache_after_htaccess</a></li><li><a href="powered_cache_auto_htaccess_update.html">powered_cache_auto_htaccess_update</a></li><li><a href="powered_cache_browser_cache.html">powered_cache_browser_cache</a></li><li><a href="powered_cache_browser_cache_assets_lifespan.html">powered_cache_browser_cache_assets_lifespan</a></li><li><a href="powered_cache_browser_cache_default_lifespan.html">powered_cache_browser_cache_default_lifespan</a></li><li><a href="powered_cache_browser_cache_lifespan.html">powered_cache_browser_cache_lifespan</a></li><li><a href="powered_cache_cache_purge_interval.html">powered_cache_cache_purge_interval</a></li><li><a href="powered_cache_cache_query_strings.html">powered_cache_cache_query_strings</a></li><li><a href="powered_cache_cdn_addresses.html">powered_cache_cdn_addresses</a></li><li><a href="powered_cache_cdn_disable.html">powered_cache_cdn_disable</a></li><li><a href="powered_cache_cdn_extensions.html">powered_cache_cdn_extensions</a></li><li><a href="powered_cache_cdn_image_extensions.html">powered_cache_cdn_image_extensions</a></li><li><a href="powered_cache_cdn_rewrite_relative_urls.html">powered_cache_cdn_rewrite_relative_urls</a></li><li><a href="powered_cache_cdn_site_hostnames.html">powered_cache_cdn_site_hostnames</a></li><li><a href="powered_cache_cdn_zones.html">powered_cache_cdn_zones</a></li><li><a href="powered_cache_default_settings.html">powered_cache_default_settings</a></li><li><a href="powered_cache_defer_exclusions.html">powered_cache_defer_exclusions</a></li><li><a href="powered_cache_delay_exclusions.html">powered_cache_delay_exclusions</a></li><li><a href="powered_cache_delayed_js_script_content.html">powered_cache_delayed_js_script_content</a></li><li><a href="powered_cache_delayed_js_script_loader.html">powered_cache_delayed_js_script_loader</a></li><li><a href="powered_cache_delayed_js_skip.html">powered_cache_delayed_js_skip</a></li><li><a href="powered_cache_delayed_js_timeout.html">powered_cache_delayed_js_timeout</a></li><li><a href="powered_cache_disable_advanced_cache_notices.html">powered_cache_disable_advanced_cache_notices</a></li><li><a href="powered_cache_disable_js_defer.html">powered_cache_disable_js_defer</a></li><li><a href="powered_cache_disable_js_defer_inline.html">powered_cache_disable_js_defer_inline</a></li><li><a href="powered_cache_disable_native_lazyload.html">powered_cache_disable_native_lazyload</a></li><li><a href="powered_cache_fo_allow_gzip_compression.html">powered_cache_fo_allow_gzip_compression</a></li><li><a href="powered_cache_fo_cache_ttl.html">powered_cache_fo_cache_ttl</a></li><li><a href="powered_cache_fo_css_do_concat.html">powered_cache_fo_css_do_concat</a></li><li><a href="powered_cache_fo_dashboard.html">powered_cache_fo_dashboard</a></li><li><a href="powered_cache_fo_disable.html">powered_cache_fo_disable</a></li><li><a href="powered_cache_fo_disable_css_combine.html">powered_cache_fo_disable_css_combine</a></li><li><a href="powered_cache_fo_disable_css_minify.html">powered_cache_fo_disable_css_minify</a></li><li><a href="powered_cache_fo_disable_html_minify.html">powered_cache_fo_disable_html_minify</a></li><li><a href="powered_cache_fo_disable_js_combine.html">powered_cache_fo_disable_js_combine</a></li><li><a href="powered_cache_fo_disable_js_minify.html">powered_cache_fo_disable_js_minify</a></li><li><a href="powered_cache_fo_excluded_css_files.html">powered_cache_fo_excluded_css_files</a></li><li><a href="powered_cache_fo_excluded_js_files.html">powered_cache_fo_excluded_js_files</a></li><li><a href="powered_cache_fo_google_font_display.html">powered_cache_fo_google_font_display</a></li><li><a href="powered_cache_fo_google_fonts_domain.html">powered_cache_fo_google_fonts_domain</a></li><li><a href="powered_cache_fo_js_do_concat.html">powered_cache_fo_js_do_concat</a></li><li><a href="powered_cache_fo_relative_path.html">powered_cache_fo_relative_path</a></li><li><a href="powered_cache_fo_script_loader_tag.html">powered_cache_fo_script_loader_tag</a></li><li><a href="powered_cache_fo_site_url.html">powered_cache_fo_site_url</a></li><li><a href="powered_cache_fo_style_loader_tag.html">powered_cache_fo_style_loader_tag</a></li><li><a href="powered_cache_get_page_cache_dir.html">powered_cache_get_page_cache_dir</a></li><li><a href="powered_cache_htaccess_add_cors.html">powered_cache_htaccess_add_cors</a></li><li><a href="powered_cache_htaccess_cache_control_rules.html">powered_cache_htaccess_cache_control_rules</a></li><li><a href="powered_cache_htaccess_enable_gzip_compression.html">powered_cache_htaccess_enable_gzip_compression</a></li><li><a href="powered_cache_ignored_query_strings.html">powered_cache_ignored_query_strings</a></li><li><a href="powered_cache_js_execution_methods.html">powered_cache_js_execution_methods</a></li><li><a href="powered_cache_known_headers.html">powered_cache_known_headers</a></li><li><a href="powered_cache_lazy_load_avatar.html">powered_cache_lazy_load_avatar</a></li><li><a href="powered_cache_lazy_load_enabled.html">powered_cache_lazy_load_enabled</a></li><li><a href="powered_cache_lazy_load_exclusions.html">powered_cache_lazy_load_exclusions</a></li><li><a href="powered_cache_lazy_load_html.html">powered_cache_lazy_load_html</a></li><li><a href="powered_cache_lazy_load_iframes.html">powered_cache_lazy_load_iframes</a></li><li><a href="powered_cache_lazy_load_images.html">powered_cache_lazy_load_images</a></li><li><a href="powered_cache_lazy_load_post_content.html">powered_cache_lazy_load_post_content</a></li><li><a href="powered_cache_lazy_load_post_thumbnail.html">powered_cache_lazy_load_post_thumbnail</a></li><li><a href="powered_cache_lazy_load_run_filter.html">powered_cache_lazy_load_run_filter</a></li><li><a href="powered_cache_lazy_load_skip_classes.html">powered_cache_lazy_load_skip_classes</a></li><li><a href="powered_cache_lazy_load_skip_first_nth_img.html">powered_cache_lazy_load_skip_first_nth_img</a></li><li><a href="powered_cache_lazy_load_threshold.html">powered_cache_lazy_load_threshold</a></li><li><a href="powered_cache_lazy_load_widget_text.html">powered_cache_lazy_load_widget_text</a></li><li><a href="powered_cache_lazy_load_youtube.html">powered_cache_lazy_load_youtube</a></li><li><a href="powered_cache_lazy_load_youtube_css.html">powered_cache_lazy_load_youtube_css</a></li><li><a href="powered_cache_log_destination.html">powered_cache_log_destination</a></li><li><a href="powered_cache_log_message.html">powered_cache_log_message</a></li><li><a href="powered_cache_log_message_type.html">powered_cache_log_message_type</a></li><li><a href="powered_cache_maybe_1and1_hosting.html">powered_cache_maybe_1and1_hosting</a></li><li><a href="powered_cache_mod_rewrite.html">powered_cache_mod_rewrite</a></li><li><a href="powered_cache_object_cache_dropins.html">powered_cache_object_cache_dropins</a></li><li><a href="powered_cache_object_cache_file_content.html">powered_cache_object_cache_file_content</a></li><li><a href="powered_cache_page_cache_meta_info.html">powered_cache_page_cache_meta_info</a></li><li><a href="powered_cache_page_cache_meta_params.html">powered_cache_page_cache_meta_params</a></li><li><a href="powered_cache_page_caching_buffer.html">powered_cache_page_caching_buffer</a></li><li><a href="powered_cache_post_related_urls.html">powered_cache_post_related_urls</a></li><li><a href="powered_cache_pre_htaccess.html">powered_cache_pre_htaccess</a></li><li><a href="powered_cache_preconnect_resource.html">powered_cache_preconnect_resource</a></li><li><a href="powered_cache_prefetch_dns.html">powered_cache_prefetch_dns</a></li><li><a href="powered_cache_preload_add_url_to_queue.html">powered_cache_preload_add_url_to_queue</a></li><li><a href="powered_cache_preload_expired_urls.html">powered_cache_preload_expired_urls</a></li><li><a href="powered_cache_preload_mobile_user_agent.html">powered_cache_preload_mobile_user_agent</a></li><li><a href="powered_cache_preload_post_limit.html">powered_cache_preload_post_limit</a></li><li><a href="powered_cache_preload_post_types.html">powered_cache_preload_post_types</a></li><li><a href="powered_cache_preload_public_posts_offset.html">powered_cache_preload_public_posts_offset</a></li><li><a href="powered_cache_preload_public_taxonomies_offset.html">powered_cache_preload_public_taxonomies_offset</a></li><li><a href="powered_cache_preload_request_interval.html">powered_cache_preload_request_interval</a></li><li><a href="powered_cache_preload_tax_term_args.html">powered_cache_preload_tax_term_args</a></li><li><a href="powered_cache_preload_taxonomies.html">powered_cache_preload_taxonomies</a></li><li><a href="powered_cache_preload_term_limit.html">powered_cache_preload_term_limit</a></li><li><a href="powered_cache_preload_url_request_args.html">powered_cache_preload_url_request_args</a></li><li><a href="powered_cache_preloader_max_server_load.html">powered_cache_preloader_max_server_load</a></li><li><a href="powered_cache_preloader_should_continue.html">powered_cache_preloader_should_continue</a></li><li><a href="powered_cache_rejected_cookies.html">powered_cache_rejected_cookies</a></li><li><a href="powered_cache_rejected_referrers.html">powered_cache_rejected_referrers</a></li><li><a href="powered_cache_rejected_uri_list.html">powered_cache_rejected_uri_list</a></li><li><a href="powered_cache_rejected_user_agents.html">powered_cache_rejected_user_agents</a></li><li><a href="powered_cache_sanitized_options.html">powered_cache_sanitized_options</a></li><li><a href="powered_cache_scheduled_cleanup_frequency_options.html">powered_cache_scheduled_cleanup_frequency_options</a></li><li><a href="powered_cache_site_cache_dir.html">powered_cache_site_cache_dir</a></li><li><a href="powered_cache_vary_cookies.html">powered_cache_vary_cookies</a></li></ul>
</nav>
<br class="clear">
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>