wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

"Cache Query String(s)" feature not working with Preloading of custom URLs

Open skinguru24 opened this issue 8 months ago • 1 comments

If:

  1. add for example 'attribute_color' and 'attribute_size' to Advacned Rules -> "Cache Query String(s) " ( to cache variations pages in woocommerce like https://skinguru24.hu/p/missha-magic-cushion-cover-lasting-spf50-pa-15g/?attribute_color=23+Natural+beige )

  2. add custom preloading for these variations urls using add_filter( 'rocket_preload_load_custom_urls', ... )

Then: Wp-Rocket will try preload wrong URLs like 'https://skinguru24.hu/p/missha-magic-cushion-cover-lasting-spf50-pa-15g/?attribute_color=23+Natural+beige/':

Apache logs: 111.111.111.111- - [08/May/2025:10:25:04 +0000] "GET /p/missha-magic-cushion-cover-lasting-spf50-pa-15g/?attribute_color=23+Natural+beige/ HTTP/1.0" 200 9012 "-" "WP Rocket/Preload"

The reason for the bug is in ./inc/Engine/Preload/Controller/PreloadUrl.php function 'preload_url' is using 'user_trailingslashit' function: wp_safe_remote_get( user_trailingslashit( $request['url'] ), $headers );

skinguru24 avatar May 08 '25 11:05 skinguru24

ChatGPT says to use like this ( not sure if can break some other stuff ...) :

		wp_safe_remote_get(
		    // Check if the URL contains "/?" and apply user_trailingslashit conditionally
		    (strpos($request['url'], '/?') !== false) ? $request['url'] : user_trailingslashit($request['url']),
		    $headers
		);

skinguru24-mihai avatar May 08 '25 11:05 skinguru24-mihai