Redirection Isn't Working: How to Redirect Traffic Based on Country with Cloudflare

Hi, we need to forward/redirect all traffic outside of the UAE to another site. However, I am not seeing any option to redirect the URL.

I mean, when people from the UAE visit, they will use Domain.ae. If anyone from other countries outside the UAE visits, they will be forwarded/redirected to Domain.com.

How can we achieve this using Cloudflare?

HI,

You can adapt from the example here: Single Redirects โ€” Example rules ยท Cloudflare Rules docs

Your filter expression could be:

ip.geoip.contry ne "AE"

But perhaps you should exclude redirection for SEO, marketing and other paths.

ip.geoip.country. ne "AE" and not in {"/ads.txt" "sitemap.xml" etc.}

Then you can set your target URL either as:

"https://example.com/"

if you want all visitors to land at the homepage of the target domain, or

concat("https://example.com", http.request.uri.path)

if you want visitors to land at the requested path, but in the target domain.

1 Like