PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 1.9.5
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v1.9.5
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
searchpro / inc / caching-rules.php

caching-rules.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 1.9.5, at inc/caching-rules.php

61 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Check if the server is Apache
4 if (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false) {
5
6 // Get the path to the .htaccess file
7 $htaccessFile = ABSPATH . '.htaccess';
8
9 // Check if the file exists
10 if (file_exists($htaccessFile)) {
11
12 // Get the current content of the .htaccess file
13 $currentContent = file_get_contents($htaccessFile);
14
15 // Check if caching rules are already present
16 if (strpos($currentContent, '# BerqWP Caching Rules') === false) {
17
18 // Append caching rules to the .htaccess file
19 $newRules = <<<EOD
20
21 # BerqWP Caching Rules
22 <IfModule mod_expires.c>
23 ExpiresActive On
24 ExpiresByType image/jpg "access 1 year"
25 ExpiresByType image/webp "access 1 year"
26 ExpiresByType image/jpeg "access 1 year"
27 ExpiresByType image/gif "access 1 year"
28 ExpiresByType image/png "access 1 year"
29 ExpiresByType image/svg "access 1 year"
30 ExpiresByType text/css "access 1 month"
31 ExpiresByType application/pdf "access 1 month"
32 ExpiresByType application/javascript "access 1 month"
33 ExpiresByType application/x-javascript "access 1 month"
34 ExpiresByType application/x-shockwave-flash "access 1 month"
35 ExpiresByType image/x-icon "access 1 year"
36 ExpiresDefault "access 3 days"
37 </IfModule>
38
39 <filesMatch ".(ico|pdf|flv|jpg|jpeg|webp|png|gif|svg|js|css|woff|woff2|ttf|swf)$">
40 Header set Cache-Control "max-age=96000, public"
41 </filesMatch>
42
43 <FilesMatch "\.(js|css|html|xml|txt)$">
44 SetOutputFilter DEFLATE
45 </FilesMatch>
46
47 FilesMatch "\.(pdf|doc|avi|mp4|zip)$">
48 Header set Cache-Control "max-age=604800, public"
49 </FilesMatch>
50 # BerqWP Caching Rules Ends Here
51 EOD;
52
53 // Append the new rules to the .htaccess file
54 file_put_contents($htaccessFile, $currentContent . $newRules);
55
56 }
57
58 }
59
60 }
61