How to rewrite a single query parameter through a Transform Rul

Can someone help write a single regex expression for a transform rule?

I’ve been unsuccessful at setting a transform rule to replace 1 query parameter.

We are trying to transform:

mysite.com/?alpha=something&utm...
to
mysite.com/?bravo=something&utm...

In other words we want to just change the “alpha” value in the query string to “bravo” and keep all the other utm parameters unchanged.

When I set up a Transform Rule to rewrite Query > Dynamic, Cloudflare rejects the syntax of my regex_replace. What is the correct string?

Here is what we have tried:
regex_replace(http.request.uri.path, 'alpha', 'bravo')
regex_replace(http.request.uri.path, '/alpha/', '/bravo/')
regex_replace(http.request.uri.path, /alpha/, /bravo/)
regex_replace(http.request.uri.query, ‘alpha’, ‘bravo’)

Cloudflare replies with:
Filter parsing error (1:38): regex_replace(http.request.uri.path, 'alpha', 'bravo') ^^^^^^^^^^^^^^^^^ unrecognised input (Code: 20089)

This is the right regex_replace(), except for the ', which should be ".

regex_replace(http.request.uri.query, "alpha", "bravo")

Though you could possibly use the http.request.query.path field to modify Query String, that wouldn’t make sense in your use case, as you are trying to modify the query string itself.

3 Likes

Thanks, Cloudflare accepts that regex!

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.