jfuhr
December 5, 2024, 6:45pm
1
I am attempting to create a Redirect Rule to send traffic from an old subdomain to a new one along with the query string.
ie: https://www.domain2.com/Lookup.aspx?page=1&name=Jim
The rule works, but it does not append the query string even though I have the box ticked.
I found a solution on here that says he had to change the destination to Dynamic and use the following expression:
concat("https://www.domain2.com",http.request.uri.path)
This worked for me, but shouldn’t the “Preserve query string” option do this? Does it not work or am I misunderstanding the purpose?
sjr
December 5, 2024, 7:07pm
2
A query string is the part from the ?
in a URL like…
https://example.com/showuser?name=Jim&page=1
.
Since your URL format uses a slash, you don’t have a “query string” but are passing parameters in the path.
jfuhr
December 5, 2024, 7:35pm
3
Sorry, I mistyped my example URL. I’ve edited my post to show the correct version.
ncano
December 6, 2024, 6:14pm
4
It should work: I have a rule with dynamic action set to concat("https://example.com", http.request.uri.path)
with “Preserve query string” enabled, and I see the right redirect:
% curl -svo /dev/null "https://redacted.com/myredirect?true=false"
...
< HTTP/2 301
< date: Fri, 06 Dec 2024 18:12:20 GMT
< content-type: text/html
< content-length: 167
< location: https://example.com/myredirect?true=false
< cache-control: max-age=3600
< expires: Fri, 06 Dec 2024 19:12:20 GMT
< server: cloudflare
< cf-ray: 8ede3e5e1cf37196-LHR
Having said that, there is a much easier way to do this: Redirect requests to a different hostname · Cloudflare Rules docs .