Single Redirect Rule / Maintain URI Path without Regex

Hello, I hope you’re all well! We’re attempting to use Single Redirect Rules to do the following:

  1. Check for a hostname, example.com
  2. Check for a specific country, e.g. UK
  3. Add a locale to the URL

We’ve currently been able to get the following to work:

When:

(http.host eq "example.com" and ip.geoip.country eq "GB" and http.request.uri.path eq "/" and not http.referer contains "en-")

Then: lower(concat("https://example.com", "en-", ip.geoip.country ))

This will successfully add “en-gb” to the URL and redirect the user to htttp://example.com/en-gb

My two questions are:

  1. We’re using not http.referer contains "en-" to allow a user to switch locales via a UI toggle, i.e. if “en-” is a referrer, allow the user to switch to example.com. This works in Safari, but Chrome / Chromium based browsers don’t seem to pick up the referred correctly. Any ideas on potential alternatives?

  2. Whilst the above works for the root domain, we’ve not been able to find a way to maintain the URI path so that we can add a locale to all URLs, e.g. example.com/pricingexample.com/en-gb/pricing, without resorting to using regex, which unfortunately is only available on Cloudflare Business and costs $200 a month (we’re on Pro…). Bulk redirects isn’t a suitable option as it would mean maintaining a list of all possible URLs

Thank you for your help!

Bumping this for visibility!

You can do this with an expression of concat("https://",http.host,"/en",http.request.uri.path) this will redirect matching requests (from GB) to www.example.com/en/uri_path/goes_here.

I’ve got a similar example in my demo setup but using the ‘accept-language’ header as input:

The ‘not starts_with()’ bit is important otherwise you’ll end up with a redirect loop that errors out after 50 :slight_smile: