Redirect visitors based of country

Hello there,

I have a hard time trying to create country-based redirection for my website.
So far I have found these 2 tutorials:

`youtube.com/watch?v=pnJFfFJ8hE4`
`youtube.com/watch?v=bXqtzKrWnMc`

But it is not working for me.
I have a clean cache!


Transform rule: `print.sc/r0rZIoJb9gBU`
Page rule: `print.sc/jlDW8xTYacUL`

Here is a worker:  `print.sc/ZoT6AEW7ZeLK` but it does not redirect me do example.com if I visit a website from Croatia or Bosnia.

Regards

Hi,

None of your print links are working, they all point to a parked domain, so we can’t see your rules. Please copy and paste your rule expressions instead of screenshots. This makes it easier for other users to suggest a fix.

The first YouTube tutorial was created before Redirect Rules, but, since they are now available, instead of creating a Transform Rule and a Page Rule, you should just create a Redirect Rule based on country of origin.

You should test one method at a time. If you prefer using Redirect Rules (easier), you should remove any Worker routes so that we can troubleshoot your rules. If you prefer the Workers instead of Redirect Rules, please post the content of your Worker, with preformatted text so members of this community can review it.

Hello there,

CF was paused on this web site and that makes a problem. Redirection now is working, but:

  • If i use redirect rule with this expression: concat(“/archive”, http.request.uri.path) (image bellow)

And visit link domain.com/sales from Bosnia, user will not redirect to domain.com/archive/sales, instand user will be redirect to something like: domain.com/archive/archive/archive/archive/archive/archive/archive/archive/shop

  • if I use CF country redirect example worker: https://developers.cloudflare.com/workers/examples/country-code-redirect/

And visit domain.com/shop, it will not redirect me to domain.com/archive/shop, instad it will redirect me to just domain.com/archive.

Can you pleas help me update a code?

Regards

To avoid the loop you’re seeing, you need to redirect only if the requested path does not already have “/archive”. So your expression should look like:

(ip.geoip.country in {...}) and not starts_with(http.request.uri.path, "/archive")

It look like worker redirect is little bit faster?

How we can modifly code to do same?

Regards