Allow user to access site behind workers

Hello,

I would like to add a country redirect to a site with the following scheme:

If user visits https://example1.domain from country X, I would like them to be redirected to https://example2.domain. If the user is from any other country, I would like them to be passed through to access the website at https://example1.domain.

I would setup a corresponding worker on the other domain: if someone from outside country X visits https://example2.domain, I would redirected to https://example1.domain, otherwise the user is from Country X and should be passed through to the site at https://example2.domain.

I’ve figured out how to do the redirect with workers, but I can’t figure out how to pass through the visitor to the website. Any help?

This worker looks like it will do redirects using a list, and if it’s not in the list, it will pass through:

https://developers.cloudflare.com/workers/examples/country-code-redirect

Reversing the logic should work for the second domain.

I think this is exactly what I’m looking for, thank you! Don’t know why I missed this when looking through the documentation.

1 Like