How To Redirect Users Based On Geolocation On Your WordPress Website
How is it that when you type in a .com domain in France, a website of the same brand with a .fr domain opens up?
Well, that’s because of geolocation redirect.
A lot of companies, especially the Saas and major ecommerce websites are using it.
For example, if you type in hotels.com from India you’ll be redirected to their website in.hotels.com.
Amazon and Apple have been using this technique for more than a decade.
So, what is geolocation redirect?
Geolocation redirect is a way of automatically redirecting users to the specific country or a city domain.
Based on your requirement and the user’s geolocation, you can send people to :
- A landing page that’s dedicated to their location.
- Their local language if you run a multilingual WordPress site.
- A completely separate domain.
- Anything else that meets your needs!
Can Geolocation Redirect be done in WordPress?
WordPress doesn’t include any geo-redirect functionality, which means that you’ll need to turn to some third-party geotargeting solutions.
In this post, you’ll learn how you can redirect users based on geolocation without writing a single line of code. We’ll cover two different types of redirects:
- Static – you redirect all users from a certain geolocation to a single, static URL.
- Dynamic – you redirect users to certain pages based on the initial page that they visited. This is especially helpful for language redirects because you can send users to the exact same content on the version of your site in a different language.
Keep reading for an easy step-by-step guide that anyone can follow!
What You Need To Redirect Users Based On Geolocation On WordPress
To get started, download the plugin and create a Geotargeting WP account. Once you install and activate the plugin, add your website to the Allowed domains area in the Api Keys part of your Geotargeting WP dashboard:
Then, go to GeotargetingWP → Settings in your WordPress dashboard and add your API keys to the plugin’s settings to finish the basic configuration:
Now, you’re ready to start redirecting users based on their location!
How To Set Up A Static Redirect Based On A User’s Geolocation
For this first tutorial, we’ll show you how to redirect users to a single static page based on their geolocation.
Step 1: Create A New Geo-Redirect
To create your first geo-redirect, go to GeoTargetingWP → Geo Redirects in your WordPress dashboard. Then, click Add New:
Step 2: Choose Conditions To Trigger Redirect
Next, you’ll use a combination of Redirection Rules to configure exactly which users should be redirected (and when).
For example, if you want to target users in Germany, you would make the rule Country…is equal to…Germany:
These rules let you get pretty creative with how your redirects function because you can add multiple rules to the same redirect. You can also use both AND conditions and OR conditions:
- AND groups – all the conditions must be met in order for the redirect to fire.
- OR groups – as long as one OR group’s conditions are met, the redirect will fire.
For example, let’s say that you want to redirect users who:
- Are located in Germany
- AND are not logged into WordPress
You can set up an AND group like so:
In total, you can use rule conditions like:
- Country, USA state, City
- Posts, pages, categories, tags, etc.
- User status, e.g. logged in, user role, etc.
- Device, e.g. desktop, tablet, phone
- Query parameter
And you can also just target specific URLs if needed.
Step 3: Enter Destination URL
Once you’re finished configuring your redirect rules, scroll down to the Redirection Options to finish configuring your redirect.
Enter the page that you want to redirect visitors to in the Destination URL box. Remember, for this tutorial we’re just focused on a static URL, so all you need to do is paste in the direct URL. In the next section, we’ll talk about some of the things that those placeholders let you do:
Step 4: Configure Other Basic Redirect Settings
Under the Destination URL box, you can configure some other basic settings for your redirect:
- One-time redirect – choose how often the visitor should be redirected. You can redirect every single visit, only one visit, or only one time per session.
- Exclude search engines – you can exclude crawler bots like Google from being redirected.
- Pass query string – this lets you pass query strings, like UTM tracking.
- Redirection code – by default, the plugin uses 302 temporary redirects. But you can enter a different redirect code if desired.
- IP Whitelist – this lets you exclude specific users from being redirected.
Once you’re done, click Publish to make your redirect live.
How To Set Up A Dynamic Redirect Based On A User’s Geolocation
With a dynamic redirect, you’re able to use placeholder variables to send users to different pages based on their location or the page that they try to visit.
These are especially helpful when you want to send users to a different translation of your site while still serving up the same content. Or, you could use them to create separate landing pages for different countries (or anything else!)
The main setup process is the same as the previous tutorial – the only difference is the Destination URL option. If you look below the field, you’ll see a list of potential variables:
These are what you use to create your dynamic redirect.
An Example Of Dynamically Redirecting Users Based On Location
Let’s say you have three versions of your site. The main version is English. Then, you also have German and Argentinean translations on a subdomain:
- yoursite.com – main site.
- de.yoursite.com – German translation.
- ar.yoursite.com – Argentinian translation.
You want to be able to dynamically redirect users so that if a German visitor comes to yoursite.com/example-post, they get redirected to de.yoursite.com/example-post. Likewise, an Argentinean visitor gets sent to ar.yoursite.com/example-post.
Dynamic redirects let you do that with a single set of redirect rules.
You would use the Redirection rules to target people from either Germany OR Argentina.
Then, you could use the dynamic placeholders to set up your Destination URL like this:
This tells the plugin to automatically:
- Insert the two-letter country code as the subdomain (this handles sending visitors to the proper translation).
- Append the URL path that the visitor is trying to access (this ensures they see the same content – just in a different language).
And that’s all there is to it. Using a single redirect rule, you’ll be able to dynamically send people to the proper language no matter how many different languages your site supports.
Start Redirecting Users Based On Their Location Today
Whether you want to use visitors’ locations to redirect them to a single static page or dynamically redirect them based on the content they’re looking at, you now know everything you need to get started.
Do you have any other questions about using geo-redirects on WordPress? Leave a comment!