"Cache Query String(s)" feature not working with Preloading of custom URLs
If:
-
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 )
-
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 );
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
);