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
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