It is really simple to do this withing Cloudflare.
Just go to your Website on the Cloudflare Dashboard, then go to “Rules” and “Redirect Rule” on your left menu.
From there, set a Custom Filter Expression for checking this values:
- Field = Country;
- Operator = Equals;
- Value = United States (or whatever you need).
Set the Redirect Type as Dynamic and use this expression (which actually concatenates your desired FQDN
us.domain.com with the path requested by the client):
If you’re using them, please consider to flag the Preserve Query String option.
Tried this earlier.
Tested with Speed/Observatory.
Error occurred as below
“It might have failed because your test URL
was redirected to a different domain.”