How to redirect requests based on geolocation on a Shopify site

Hi, I'm trying to run a redirect worker on my site that serve a Shopify site. It has A and CNAME record connected to Shopify. The worker supposed to run on the root url eg. domain.com, and redirect the request to another url (eg. domain.hk) based on user's geolocation. Will not redirect if there's no matching country. To get a worker running, I stumbled upon the step to add Custom Domain which it mentioned the domain has been taken. My questions are, am I doing it correctly? is my requirement technically possible? There's another challenge of, not being able to set the DNS record to Shopify as Proxied.
4 Replies
omar4289
omar428913mo ago
You can do it through a worker that is set to intercept requests to your route You can achieve it by returning redirects
Royyyyy
RoyyyyyOP13mo ago
Hi @omar , thank you so much for responding. Do you mind pointing me to the related docs for this? I have less domain knowledge on Cloudflare, I understand your suggestion but I'm afraid I'm less sure on how to achieve it.
omar4289
omar428913mo ago
Hi @Royyyyy , you will need to: 1. Create a worker that reads the cf property in the request (https://developers.cloudflare.com/workers/runtime-apis/request/#incomingrequestcfproperties). This worker will send a redirect (3xx status) to the nearest place 2. Create a route so that your worker intercepts all incoming requests to your website https://developers.cloudflare.com/workers/configuration/routing/routes/
Routes · Cloudflare Workers docs
Routes allow users to map a URL pattern to a Worker. When a request comes in to the Cloudflare network that matches the specified URL pattern, your …
Request · Cloudflare Workers docs
The Request interface represents an HTTP request and is part of the Fetch API.
Royyyyy
RoyyyyyOP12mo ago
@omar Hmmmm, based on the requirement (https://developers.cloudflare.com/workers/configuration/routing/routes/#set-up-a-route), I do not have Proxied (orange-clouded) DNS record. Is it still technically feasible? Or should I look into how do I make the DNS to Proxied? Last I tried, it doesn't seems allowed. hey @omar , if you have time, could you please help provide your insight on this? Appreciated !
Want results from more Discord servers?
Add your server