Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
Skip404 | |
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addRules | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
removeRules | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | namespace NewfoldLabs\WP\Module\Performance\BurstSafetyMode; |
3 | |
4 | use function WP_Forge\WP_Htaccess_Manager\addContent; |
5 | use function WP_Forge\WP_Htaccess_Manager\removeMarkers; |
6 | |
7 | /** |
8 | * Skip 404 cache type. |
9 | */ |
10 | class Skip404 { |
11 | /** |
12 | * The file marker name. |
13 | */ |
14 | const MARKER = 'Newfold Skip 404 Handling for Static Files'; |
15 | |
16 | /** |
17 | * Constructor. |
18 | */ |
19 | public function __construct() { |
20 | $this->addRules(); |
21 | } |
22 | |
23 | |
24 | /** |
25 | * Add our rules to the .htacces file. |
26 | */ |
27 | public static function addRules() { |
28 | $content = <<<HTACCESS |
29 | <IfModule mod_rewrite.c> |
30 | RewriteEngine On |
31 | RewriteCond %{REQUEST_FILENAME} !-f |
32 | RewriteCond %{REQUEST_FILENAME} !-d |
33 | RewriteCond %{REQUEST_URI} !(robots\.txt|ads\.txt|[a-z0-9_\-]*sitemap[a-z0-9_\.\-]*\.(xml|xsl|html)(\.gz)?) |
34 | RewriteCond %{REQUEST_URI} \.(css|htc|less|js|js2|js3|js4|html|htm|rtf|rtx|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|avif|avifs|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|webm|mpp|otf|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|_ttf|wav|wma|wri|woff|woff2|xla|xls|xlsx|xlt|xlw|zip)$ [NC] |
35 | RewriteRule .* - [L] |
36 | </IfModule> |
37 | HTACCESS; |
38 | |
39 | addContent( self::MARKER, $content ); |
40 | } |
41 | |
42 | /** |
43 | * Remove our rules from the .htaccess file. |
44 | */ |
45 | public static function removeRules() { |
46 | removeMarkers( self::MARKER ); |
47 | } |
48 | } |