IP Geolocation and localizing by geolocation

#1

I am attempting to set up a multilingual wordpress instance with cloudflare CDN in front.

The site is completely read-only and links to other service endpoints where users can interact with the company.

I would like to support caching the localized pages in cloudflare and redirecting visitors to different localized uris server-side by geo-location but I find I cannot in good conscience call the project done unless I have assurances that cloudflare does not cache “localization redirects” or if it does then the cache is partitioned in the CDN by geo location ( meaning geo country code is used in the CDN cache key ). Note a “localization redirect” is just a redirect due to us detecting they are at the default uri and need to go to a localized uri valid for their country.

Imagine if a client originating from France requested my non-french, not localized uri path and the cloudflare CDN had a redirect cached to the italian path due to previous activity of a client originating from Italy. This would not be good.

I also do not want to exclude the “default landing page” from being cached because it will have the default language content on it if no redirect is required. Meaning the server controls if the user receives a redirect or page content based on where they are in the world.

Right now my group is open to using browser local detection and client side javascript initiated redirects, but they would like to see if this approach is possible first.

The way I see it I need to ensure server side redirects due to localization detection are not cached or ensure that the CDN when IP Geolocation is on keeps separate cache pools by Geolocation.

I am very new to cloudflare so I unfortunately have many unknowns here.

If anyone has an exceedingly strong argument against server-side Geo-based localization detection and redirects I would also appreciate your viewpoints.

I think browser language client side detection works amazingly and nearly every browser runs with javascript enabled these days, but I am not sure how that plays with search engine optimization concerns.

I know cloudflare also has a “serverless” offering but I lack experience and knowledge to say it can be used here much less describe how.

Cheers!

0 Likes

#2

CF will never cache a 302 redirect.

If you do use a 301 redirect, it will only be cached in the one datacenter. CF caches aren’t replicated whatsoever.

Cloudflare does not cache HTML by default anyways, so in order to achieve this you must not use “cache everything”.
See

0 Likes

#3

Thank you for your reply @Judge !

I am aware that Cloudflare does not cache html by default and I have enabled the “cache-everything” behavior.

Thank you for also clarifying that Cloudflare does not replicate their cache between datacenters.

I am still curious, is there any way I can alter the cache-key to include the geo-location header Cloudflare adds when geo-location is enabled?

Or is there an integration in Cloudflare like a lambda/serverless integration such that I can change the client’s request or the CDN’s response ( for example make it a redirect ) and reference the Geo-Location header value generated by CloudFront?

( Thinking something like AWS’ Cloudfront lambda-at-edge features - specifically viewer-request handlers for the above. )

0 Likes