Can you confirm if this is correct? If yes, implement it in your plugin
– first of all this is not dully correct or fully wrong. Let me explain further.
The first problem is you did if URI contains fbclid
then remove the query string. Which is right is your case but can be wrong in many other cases. As an example if your URI is something like https://example.com/what-is-fbclid/?fbclid=123
then it will output https://example.com/what-is-fbclid/
but what if you have a bunch of other query params attached to it which you would like to keep.
For example imagine an URL like https://example.com/what-is-fbclid/?fbclid=123&foo=bag&selected_item=123
in this case you would like to remove the fbclid
while keeping the other query params intact.
Now this would only be possible with the help of Regex (Regular Expressions) which is only available for Cloudflare Business and Enterprise plan users.
So, using the worker which also has 100,000 requests/day for free and after that charges a very nominal cost – would provide much better value as it is not only handling the URL query params properly with regex but also has a much better cache bypass logic which works really great for eCommerce sites. Also with workers, there are no cache buster query string. So, it’s a win-win-win everywhere.
———————-
Now coming to what’s the best possible Cloudflare Transform Rule for handling query parameters, here is what I will suggest –
Rule Name: Remove Unnecessary Query Params
When incoming requests match…
Field: URI Query String
Operator: Matches Regex
Value:
(fbclid|fb_action_ids|fb_action_types|fb_source|_ga|age-verified|ao_noptimize|usqp|cn-reloaded|klaviyo|gclid|utm_source|utm_medium|utm_campaign|utm_content|utm_term|ref|utm_term|hemail|amp)=[a-zA-Z0-9]+
Then
Rewrite
Path: Preserve
Query
Rewrite to: Dynamic
Value:
regex_replace(http.request.uri.query, "(fbclid|fb_action_ids|fb_action_types|fb_source|_ga|age-verified|ao_noptimize|usqp|cn-reloaded|klaviyo|gclid|utm_source|utm_medium|utm_campaign|utm_content|utm_term|ref|utm_term|hemail|amp)=[a-zA-Z0-9]+", "")
Screenshot: https://i.imgur.com/NM8bUou.jpeg
P.S.: Regex match is only available for Cloudflare Business and Enterprise plan users.
——————
Alternatively, if you use the Transform Rule the way you are using – as I said before it will lead to removing all query param when one of them is present. So, if you are sure that you will never have situations like where you will have both query params like fbclid
which you would like to remove along with other query params that you would like to keep. Then you can definitely do what you are doing.
But again this will not be done automatically by the plugin for everyone as there might be sites whose use cases are not that simple and they might need to remove certain query params while keeping the others. So, the worker option is still the best.