Skip to content

Commit 4b102ae

Browse files
committed
Use a better rules
1 parent caa2485 commit 4b102ae

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

includes/Cloudflare/CloudflareFeaturesManager.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,23 @@ private function update_htaccess_header( $image_settings, $fonts_enabled ) {
8282

8383
if ( $mirage_enabled || $polish_enabled || $fonts_enabled_flag ) {
8484
$rules = array(
85+
'<IfModule mod_rewrite.c>',
86+
"\tRewriteEngine On",
87+
'',
88+
"\t# don’t flag any admin or API endpoints",
89+
"\tRewriteCond %{REQUEST_URI} !/wp-admin/ [NC]",
90+
"\tRewriteCond %{REQUEST_URI} !/wp-login\\.php [NC]",
91+
"\tRewriteCond %{REQUEST_URI} !/wp-json/ [NC]",
92+
"\tRewriteCond %{REQUEST_URI} !/xmlrpc\\.php [NC]",
93+
"\tRewriteCond %{REQUEST_URI} !/admin-ajax\\.php [NC]",
94+
'',
95+
"\t# if we passed all those, set our CF_OPT flag",
96+
"\tRewriteRule .* - [E=CF_OPT:1]",
97+
'</IfModule>',
98+
'',
8599
'<IfModule mod_headers.c>',
86-
"\tHeader set Set-Cookie \"nfd-enable-cf-opt={$header_value}; path=/; Max-Age=86400; HttpOnly\" env=nfd_cf_opt",
100+
"\tHeader set Set-Cookie \"nfd-enable-cf-opt={$header_value}; path=/; Max-Age=86400; HttpOnly\" env=CF_OPT",
87101
'</IfModule>',
88-
'# Exclude admin and API paths',
89-
'SetEnvIf Request_URI "^/wp-admin/" no_nfd_cf',
90-
'SetEnvIf Request_URI "^/wp-json/" no_nfd_cf',
91-
'SetEnvIf Request_URI "^/xmlrpc.php" no_nfd_cf',
92-
'SetEnvIf Request_URI "^/wp-login.php" no_nfd_cf',
93-
'SetEnvIf Request_URI "^/admin-ajax.php" no_nfd_cf',
94-
'# Apply CF cookie on all non-admin, non-API requests',
95-
'SetEnvIf Request_URI ".*" nfd_cf_opt=!no_nfd_cf',
96102
);
97103
}
98104

0 commit comments

Comments
 (0)