Hello,
That’s a tricky one.
With Transform Rules - Rewrite URL, you can only rewrite the path, the query, or both. The ?
delimiter is not part of either the http.request.uri.path
or the http.request.uri.query
field. However, since the URL contains &
where a ?
should be, Cloudflare is treating what you consider your query string as part of the path element (http.request.uri.path
= /&query...
), while http.request.uri.query
is left empty.
What I found that (kind of) works is this:
Rewrite Path (Dynamic): regex_replace(http.request.uri.path, "&.*", "")
Here we’re telling TR to replace
/&some=query&etc
/some/path/&some=query&etc
respectively with
/
/some/path/
Then
Rewrite Query (Dynamic): regex_replace(http.request.uri, ".*&", "")
Since http.request.uri.path
has already been modified, we take http.request.uri
(/some/path/&some=query
) to extract the query string, removing everything up to the first &
.
I said it “kind of” worked because, strangely enough, in my tests it only worked when the path ends with a trailing slash immediately preceding the &
. So it worked for
example.com/hello-world/&some=query
but not with
example.com/hello-world&some=query
Your URL examples indicate your URLs do not end with a trailing slash. Perhaps another @MVP with experience in using regex with Transform Rules could suggest a better regex expression for this case.
But somehow a Redirect Rule with a regex_replace and Full URI worked without the trailing slash:
Type: Dynamic
Expression: regex_replace(http.request.full_uri, "/(.*)&", "/${1}?")
I hope it works for you. As with everything related to Regex, make sure you test, test, then test again.