• Resolved Zoltan Baffy

    (@macika)


    How can I achieve “Ignore Query String” like some CDNs do?

    Whether the url is

    https://www.example.com/cars
    https://www.example.com/cars?=123
    https://www.example.com/cars?data=123
    https://www.example.com/cars?selection=abc

    W3TC should only cache https://www.example.com/cars.
    Now if I open https://www.example.com/cars?=123 then W3TC doesn’t cache the cars page. It should, no matter if “Cache URIs with query string variables” is turned off, since I don’t want hundreds of cached occurances of the same cars page.

    As I remember it worked in 0.9.5.4! Somehow it was revised in later versions.

    • This topic was modified 3 years, 9 months ago by Zoltan Baffy.
    • This topic was modified 3 years, 9 months ago by Zoltan Baffy.
    • This topic was modified 3 years, 9 months ago by Zoltan Baffy.
    • This topic was modified 3 years, 9 months ago by Zoltan Baffy.
    • This topic was modified 3 years, 9 months ago by Zoltan Baffy.
    • This topic was modified 3 years, 9 months ago by Zoltan Baffy.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Zoltan Baffy

    (@macika)

    Solved!

    In w3-total-cache\PgCache_ContentGrabber.php:

    		 * Skip if there is query in the request uri
    		 */
    		$this->_preprocess_request_uri();
    
    		if ( !empty( $this->_request_url_fragments['querystring'] ) ) {
    			$should_reject_qs =
    				( !$this->_config->get_boolean( 'pgcache.cache.query' ) ||
    				$this->_config->get_string( 'pgcache.engine' ) == 'file_generic' );
    
    			if ( $should_reject_qs &&
    				$this->_config->get_string( 'pgcache.rest' ) == 'cache' &&
    				Util_Environment::is_rest_request( $this->_request_uri ) ) {
    				$should_reject_qs = false;
    			}
    
    			if ( $should_reject_qs ) {
    				$this->cache_reject_reason = 'Requested URI contains query';
    				$this->process_status = 'miss_query_string';
    
    				return false;
    			}
    		}

    I just delete everything in this, it was the easiest method to eliminate it without an error.

    Kept just this:

    		/**
    		 * Skip if there is query in the request uri
    		 */
    		$this->_preprocess_request_uri();
    
    		if ( !empty( $this->_request_url_fragments['querystring'] ) ) {
    
    		}

    Not an elegant and correct method, but it works!

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @macika

    Thank you for providing the solution.
    As this works in your case, it might not work in different setups so we will make sure to check and test this to see if it may cause any issues.
    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Ignore Query String’ is closed to new replies.