'Remove query params that is not part of a list

aI have an apache http server and currently implemented the following line to ignore the query params and cache the page.

CacheIgnoreURLSessionIdentifiers utm_source utm_campaign utm_medium utm_content

But if a user puts a new query param that is not specified in the CacheIgnoreURLSessionIdentifiers, the server is not serving the page from cache. Is there a way to allow only the specified query params and remove the query params that is not in the list.

I also tried the following

Given the url: https://test.com?utm_source=1234&utm_campaign=asdf&new_param=33

I created the rule

RewriteEngine On 
RewriteCond %{QUERY_STRING} ^(utm_.*)$
RewriteRule (.*) $1?%1

but still its copying all the query params.

Is there a way to filter out only valid query params that I will specify?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source