Geo routing using slug

HI All,

I have this question with one of our clients; they need to do geo-routing to a certain part of the site.

Ex:

  • Web page has language change support (two languages CN / EN)

  • CN customers should go to CN translated pages.

  • EN customers should go to EN translated pages.

  • Traffic will route through Cloudflare to the website and we don’t use subdomains here. we use slugs.

Ex:
example.com/cn
example.com/en

do we have option to do followings via Cloudflare business plan?

  1. Detect the IP
  2. if the traffic from China redirect to example.com/cn if it is other than from china the traffic should go to english site which is example.com/en .
  3. The site is created with Wordpress CMS, and the WPML plugin is used to translate the pages.

Your support in this regard is highly appreciated.

Best,
Dan

Hi Dan,
Have you tried to set up a Redirect Rule?

Or Workers?

Hi Nic,

Let me try these options and let you know. May i keep this open until i do it ?

Hi @dan89,

You can achieve this using two Dynamic Redirect rules. For example, if a user from China navigates to example.com/about.html, they will be redirected to example.com/cn/about.html. However, if they explicitly go to example.com/en/about.html, then they will be shown the English version of the page. You may want to exclude certain paths like example.com/static/ or example.com/favicon.ico, but I’ll leave doing that as an exercise for the reader :slight_smile:

Redirect China

When incoming requests match…

(
    http.host == "example.com"
    and
    ip.geoip.country == "CN"
    and
    not (
        starts_with(http.request.uri.path, "/en/")
        or
        starts_with(http.request.uri.path, "/cn/")
    )
)

Then…
URL redirect
Type: Dynamic
Expression: concat("/cn", http.request.uri)
Status code: 302

Redirect Other

When incoming requests match…

(
    http.host == "example.com"
    and
    ip.geoip.country != "CN"
    and
    not (
        starts_with(http.request.uri.path, "/en/")
        or
        starts_with(http.request.uri.path, "/cn/")
    )
)

Then…
URL redirect
Type: Dynamic
Expression: concat("/en", http.request.uri)
Status code: 302

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.