Check REQUEST_URI not $_GET when skipping supercache
-
Hello,
I would like to use wp super-cache in expert mode but I have found a problem which prevents me from doing so.
I have a number of pages that are auto generated and use the wordpress internal add_rewrite_rule() function. For example, accessing https://www.emmywatch.com/movement/omega–560 on my site actually results in wordpress rewriting the url to https://www.emmywatch.com/db/index.php?page=2109&movslug=omega–560, which is processed by my site. The call I use to do this in wordpress is shown below:
add_rewrite_rule('^' . $slug . '/movement/(.*)/?', 'index.php?page_id=' . $pageId . '&movslug=$matches[1]', 'top');
Now of course I’d like these pages (/movement/omega–560, etc) to use the supercache so that I can serve them directly from nginx. But the problem is within the wp supercache plugin code, it is checking if $_GET is empty, if it is not empty supercache will never be used. Instead, you should be checking REQUEST_URI to see if there is a query string present, this will fix the issue and allow for others to use auto generated pages with add_rewrite_rule() like I am, otherwise these pages will never use the supercache.
$dir = get_current_url_supercache_dir(); $supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $home_url[ 'host' ]); if ( ! empty( $_GET ) || isset( $wp_super_cache_query[ 'is_feed' ] ) || ($super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) { wp_cache_debug( 'Supercache disabled: GET or feed detected or disabled by config.', 2 ); $super_cache_enabled = false; }
The above should use $_SERVER[‘REQUEST_URI’] (instead of checking !empty($_GET)) to check for the presence of a query string ‘?’ instead.
- The topic ‘Check REQUEST_URI not $_GET when skipping supercache’ is closed to new replies.