Skip to content

WordPress Geo Redirection using Cloudflare

Website Developer Sydney

WordPress Geo Location Redirection fast SEO friendly

So the problem for us started out as this. We have a WordPress website that has content that is location specific. This content has been setup in WordPress using Elementor with essentially a duplication of the core site pages like contact-us, about-us, homepage, services, etc that had specific content if someone was in Europe vs Australia.

So for example, the home page has images related to either Australia or UK

. WP URL GEO Redirection

WP Geor Redirection based on Country

How this was created

Kind of a different story than the context of this post, but within Elementor Header we have created 4 headings. These headings use the flags with set links in them to allow someone to redirect to a URL that will show UK content or not.

Each of the 4 headers have one of two menus, either a UK menu with links to all the UK content specific pages, or NON UK pages that are intended for all other countries but specifically Australia.

The idea is that just like a normal site you may have: home, about-us, contact-us etc. giving domain.com/contact-us/ for the base of the site, then content specific for UK with domain.com/contact-us/uk/ taking the user to a UK specific version of the contact us page. All the headers linking as they should to the relevant versions or the pages.

The Redirection Problem

So we have several redirection needs.

1. Google indexes the content and in time displays home pages linking that briefs the relevant content for searches in Europe that are SEO friendly there and the same for Australia.

2. A user directly entering a URL like domain.com/contact-us  or domain.com/contact-us/ needs to end up at the correct pages based on their Geo Location. This had to work for all pages on the site with specific content.

3. We have the pages cached and on page code optimised for SEO. Nothing we do can slow this down or mess with this.

4. It has to be fast and apparently effortless for the end user.

 

WordPress GIO Redirection Plugins

We initially looked for the easy way out with the possibility of using a simple GIO Redirection plugin the WP site. This would work well for a single page like the home page, but we could not find a free module that would handle all our requirements. Only about 10 pages but not just 1.

SEO and PageSpeed Considerations

Because our site has been optimised for WordPress SEO with a combination of:

  • Rank Math
  • WP Rocket
  • Cloudflare
  • Cloudfront CDN
  • Imagify

To name a few, we have a comprehensive setup that delivers extremely fast content worldwide. The configuration of Cloudfront is using the free tier service to optimise many things, but specifically DNS services for this site. One of the Cloudflare services that is free to use is Geo Redirection using Transform Rules.

How We Implemented Geo Redirection with Cloudflare

Login to Cloudflare and select your domain in question.

Select Rules / Transform Rules

Cloudflare Transform Rules for Geo Redirection

Create a New Rewrite URL

Wordpress Cloudflare Geo Redirect Rule

Fill in the fields for either Country or Continent, equals, Europe in our example

AND

URI equals /.  (Representing the home page or domain.com)

The Rewrite a Path with a Dynamic rule: concat(http.request.uri.path, “/home/uk/”)

Note that in our example above, the home page of the site outside Europe loads on domain.com and the home page of the Europe pages is domain.com/home/uk/. This is why our rule adds “/home/uk/“  for the home page rule.

Wordpress SEO Friendly Redirections Based on Country

Save the rule

We then create other rules for other pages on your site. We specifically wanted an end user to be able to type the rule URL with / at the end or use the URL to a page without the /. So for example the domain.com/bookkeeping-services/ is an example of a page. We want a user to be able to type domain.com/bookkeeping-services, with the redirection delivering the user to /bookkeeping-services/uk/ if they are in Europe.

This is achieved by searing for bookkeeping-services without the UK, to take into account that if someone is already searching for this address typing /uk/ in the URL, then we do not want to add a second /uk/ to the url making it invalid domain.com/bookkeeping-services/uk/uk/

To achieve this we set the following rule.

cloudflare geo redirection dynamic rules

Not how it is making sure there is not already a “uk” in the page name before adding it to the URL. This worked well and ensured that all our goals were met.

I noted that there is a real lack of information about dynamic rules and how to set them up. Some examples but very few with dynamic redirections. Some people discussing this and asking questions, but I also noted that the coders answering the questions often referred people to create worker processes in Cloudflare, which I don’t really see the point for something as simple as this.

Anyway good luck if you are replicating this process and feel free to post comments that may help others.

Leave a Reply

Your email address will not be published. Required fields are marked *