From f9eaee616d04955f30587289e317a4cd5e01b639 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Sun, 7 Jul 2024 11:09:38 +0200 Subject: [PATCH] refactor nginx and htaccess config examples (#302) * simplify the code to generate config examples * remove some redundant HTML escapes * hdd.htaccess: fix rewrite condition for empty query string * apc.nginx: remove STRONG tags which are not supported inside TEXTAREA * hdd.nginx: only add "gzip_static" directive to nginx HDD example, if enabled * memcached.nginx: remove "gzip_static" directive --- inc/setup/cachify.apc.htaccess.php | 17 +++------ inc/setup/cachify.apc.nginx.php | 17 +++------ inc/setup/cachify.hdd.htaccess.php | 50 ++++++++++----------------- inc/setup/cachify.hdd.nginx.php | 2 ++ inc/setup/cachify.memcached.nginx.php | 3 -- 5 files changed, 31 insertions(+), 58 deletions(-) diff --git a/inc/setup/cachify.apc.htaccess.php b/inc/setup/cachify.apc.htaccess.php index 48acb9f8..ad650c32 100644 --- a/inc/setup/cachify.apc.htaccess.php +++ b/inc/setup/cachify.apc.htaccess.php @@ -8,11 +8,9 @@ /* Quit */ defined( 'ABSPATH' ) || exit; -$beginning = '<Files index.php> - php_value auto_prepend_file '; - -$ending = '/cachify/apc/proxy.php -</Files>'; +$htaccess = ' + php_value auto_prepend_file ' . WP_PLUGIN_DIR . '/cachify/apc/proxy.php +'; // phpcs:disable Squiz.PHP.EmbeddedPhp ?> @@ -21,10 +19,5 @@

+ echo esc_html( $htaccess ); +?> diff --git a/inc/setup/cachify.apc.nginx.php b/inc/setup/cachify.apc.nginx.php index 0408637c..72e11ffe 100644 --- a/inc/setup/cachify.apc.nginx.php +++ b/inc/setup/cachify.apc.nginx.php @@ -8,17 +8,15 @@ /* Quit */ defined( 'ABSPATH' ) || exit; -$beginning = 'location ~ .php { +$nginx_conf = 'location ~ .php { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; - fastcgi_param PHP_VALUE auto_prepend_file='; - -$ending = '/cachify/apc/proxy.php; + fastcgi_param PHP_VALUE auto_prepend_file=' . WP_PLUGIN_DIR . '/cachify/apc/proxy.php; location ~ /wp-admin/ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; - fastcgi_param PHP_VALUE auto_prepend_file=; + fastcgi_param PHP_VALUE auto_prepend_file=; } }'; @@ -29,12 +27,7 @@

+ echo esc_html( $nginx_conf ); +?> () diff --git a/inc/setup/cachify.hdd.htaccess.php b/inc/setup/cachify.hdd.htaccess.php index e470b0e9..4c95b6d7 100644 --- a/inc/setup/cachify.hdd.htaccess.php +++ b/inc/setup/cachify.hdd.htaccess.php @@ -8,9 +8,8 @@ /* Quit */ defined( 'ABSPATH' ) || exit; -$beginning = '# BEGIN CACHIFY -<IfModule mod_rewrite.c> - # ENGINE ON +$htaccess = '# BEGIN CACHIFY +; RewriteEngine on # set hostname directory @@ -24,35 +23,31 @@ RewriteRule .* - [E=CACHIFY_DIR:%{REQUEST_URI}] RewriteCond %{REQUEST_URI} ^$ RewriteRule .* - [E=CACHIFY_DIR:/] -{{GZIP}} - # Main Rules - RewriteCond %{HTTP_ACCEPT} .*text/html.* - RewriteCond %{REQUEST_METHOD} GET - RewriteCond %{QUERY_STRING} ="" - RewriteCond %{REQUEST_URI} !^/(wp-admin|wp-content/cache)/.* - RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_ - RewriteCond '; +'; -$gzip = ''; if ( Cachify_HDD::is_gzip_enabled() ) { - $gzip = ' + $htaccess .= ' # gzip RewriteRule .* - [E=CACHIFY_SUFFIX:] - <IfModule mod_mime.c> + ; RewriteCond %{HTTP:Accept-Encoding} gzip RewriteRule .* - [E=CACHIFY_SUFFIX:.gz] AddType text/html .gz AddEncoding gzip .gz - </IfModule> + ; '; } -$beginning = str_replace( '{{GZIP}}', $gzip, $beginning ); -$middle = '/cache/cachify/%{ENV:CACHIFY_HOST}%{ENV:CACHIFY_DIR}index.html%{ENV:CACHIFY_SUFFIX} -f - RewriteRule ^(.*) '; - -$ending = '/cache/cachify/%{ENV:CACHIFY_HOST}%{ENV:CACHIFY_DIR}index.html%{ENV:CACHIFY_SUFFIX} [L] -</IfModule> +$htaccess .= ' + # Main Rules + RewriteCond %{HTTP_ACCEPT} .*text/html.* + RewriteCond %{REQUEST_METHOD} GET + RewriteCond %{QUERY_STRING} ^$ + RewriteCond %{REQUEST_URI} !^/(wp-admin|wp-content/cache)/.* + RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_ + RewriteCond ' . WP_CONTENT_DIR . '/cache/cachify/%{ENV:CACHIFY_HOST}%{ENV:CACHIFY_DIR}index.html%{ENV:CACHIFY_SUFFIX} -f + RewriteRule ^(.*) ' . wp_make_link_relative( content_url() ) . '/cache/cachify/%{ENV:CACHIFY_HOST}%{ENV:CACHIFY_DIR}index.html%{ENV:CACHIFY_SUFFIX} [L] +; # END CACHIFY'; // phpcs:disable Squiz.PHP.EmbeddedPhp @@ -62,15 +57,8 @@

+ echo esc_html( $htaccess ); +?>

    @@ -83,7 +71,7 @@

  1. <IfModule mod_cache.c>
    -CacheDisable /
    +  CacheDisable /
     </IfModule>
  2. diff --git a/inc/setup/cachify.hdd.nginx.php b/inc/setup/cachify.hdd.nginx.php index 38b001c6..18f56d68 100644 --- a/inc/setup/cachify.hdd.nginx.php +++ b/inc/setup/cachify.hdd.nginx.php @@ -13,9 +13,11 @@