#How to redirect requests based on geolocation on a Shopify site

7 messages · Page 1 of 1 (latest)

valid pelican
#

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.

weak jay
#

You can do it through a worker that is set to intercept requests to your route

#

You can achieve it by returning redirects

valid pelican
#

Hi @weak jay , 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.

weak jay
#

Hi @valid pelican , 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 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 …

The Request interface represents an HTTP request and is part of the Fetch API.

valid pelican