@@ -300,22 +300,27 @@ private function generate_section( &$rules, $mime_types, $section ) {
300300 $ subrules = Dispatcher::nginx_rules_for_browsercache_section ( $ this ->c , $ section );
301301 $ rules .= ' ' . implode ( "\n " , $ subrules ) . "\n" ;
302302
303- if ( ! $ this ->c ->get_boolean ( 'browsercache.no404wp ' ) ) {
304- $ wp_uri = network_home_url ( '' , 'relative ' );
305- $ wp_uri = rtrim ( $ wp_uri , '/ ' );
306- $ extensions_active = $ this ->c ->get_array ( 'extensions.active ' );
307-
308- if ( 'other ' === $ section && array_key_exists ( 'imageservice ' , $ extensions_active ) ) {
309- $ rules .= "\n" . ' location ~* ^(?<path>.+)\.(jpe?g|png|gif)$ { ' . "\n" .
310- ' if ( $http_accept !~* "webp|\*/\*" ) { ' . "\n" .
311- ' break; ' . "\n" .
312- ' } ' . "\n\n" .
313- ' ' . implode ( "\n " , Dispatcher::nginx_rules_for_browsercache_section ( $ this ->c , $ section , true ) ) . "\n" .
314- ' add_header Vary Accept; ' . "\n" .
315- ' try_files ${path}.webp $uri /index.php?$args; ' . "\n" .
316- ' } ' . "\n\n" ;
303+ // Add rules for the Image Service extension, if active.
304+ if ( 'other ' === $ section && array_key_exists ( 'imageservice ' , $ this ->c ->get_array ( 'extensions.active ' ) ) ) {
305+ $ rules .= "\n" . ' location ~* ^(?<path>.+)\.(jpe?g|png|gif)$ { ' . "\n" .
306+ ' if ( $http_accept !~* "webp|\*/\*" ) { ' . "\n" .
307+ ' break; ' . "\n" .
308+ ' } ' . "\n\n" .
309+ ' ' . implode ( "\n " , Dispatcher::nginx_rules_for_browsercache_section ( $ this ->c , $ section , true ) ) . "\n" .
310+ ' add_header Vary Accept; ' . "\n" ;
311+
312+ if ( $ this ->c ->get_boolean ( 'browsercache.no404wp ' ) ) {
313+ $ rules .= ' try_files ${path}.webp $uri =404; ' ;
314+ } else {
315+ $ rules .= ' try_files ${path}.webp $uri /index.php?$args; ' ;
317316 }
318317
318+ $ rules .= "\n" . ' } ' . "\n\n" ;
319+ }
320+
321+ if ( ! $ this ->c ->get_boolean ( 'browsercache.no404wp ' ) ) {
322+ $ wp_uri = network_home_url ( '' , 'relative ' );
323+ $ wp_uri = rtrim ( $ wp_uri , '/ ' );
319324 $ rules .= ' try_files $uri $uri/ ' . $ wp_uri . '/index.php?$args; ' . "\n" ;
320325 }
321326
0 commit comments