How to create a Geo Redirection

Creating your first redirection is pretty easy. They work as a normal post or page, you can set them to draft, publish, schedule or send it to trash. Each redirection is based on 3 things:

  • Title: Just give a name to your redirection
  • Redirection rules: Here we define a set of rules that will determine if the redirection it's performed or not.
  • Redirection options: The different settings for the redirection being the main field, the destination url.

Redirection rules

redirection rules

On this section you can combine multiple rules between each other and is the most powerful part. You can create group of rules using AND or OR buttons.

For example on the screenshot above the redirection will be performed only if the user is located in the cart page, and is not logged in and his country is US. If those three statements are true the redirection will be performed.

That rule for example could be extended with an OR group of other rules and say for example redirect if the user is from Canada. So either the user is from Canada OR the three rules above match, the redirection will be performed.

You need to be careful to not overlap rules. For example if you do the following to redirect all user from US except the ones that are in contact page and you do the following:

rule 1

You can also nest multiple rules by using Global Rules. When doing this, the Global Rules will apply always as an AND in conjunction with each of the normal Rules

In the next example the redirection will happen if the user did not arrive from another page of your website AND the user is from Vietnam OR the user is from Australia. global-rule

On this example if the user is from US and he is on the Contact page will be redirect because rule group #2 overwrite rule group #1. Instead you need to add both rules using the AND button:

rule 2

It's important to add geo rules as the last rule of each group. That way is a prior rule fails, the geo rule won't run and you will save requests

A useful tip to keep in mind when geotargeting by zip codes is that we can use the * as a placeholder to replace a series of numbers. As we see in the following example 72*, equals all zip codes beginning with 72, such as 72345 or 72134.

zip-codes
Check our complete guide on how to redirect users by location.

Redirection Options

redirection options

On this section you find the different options for this redirection:

  • Destination URL: Is the url that you are redirecting the users to. You can use dynamic placeholders in here.
  • Exclude Child pages from redirect: If you are redirecting all UK users to https://yourdomain.com/uk/ and you don't have other rules, you will need to exclude child pages to avoid a loop when a user enter a page such as https://yourdomain.com/uk/child/
  • One time redirect?: You have three options to choose. "No" will redirect users every time. "Yes" will redirect users one time a save a cookie to never redirect them again unless the user clear his cookies."Yes, once per session" will create a cookie that when the user close the browser will be deleted and next time he visits the site will be redirected again.
  • Remove two letter codes: If you use {{request_path}} and two letter codes, check this option to avoid loops.
  • Exclude Search engines: By default you don't want to redirect search engines, and just do it to user.
  • Pass query string: Check this option if you want to pass the original query string to destination url.
  • Redirection code: Which status code to use on redirection. By default it's a 302 permanent redirect.
  • Ip whitelist: You can add as many IPs as needed to be excluded from the redirection.

Redirection Message

When Ajax mode is used, the user will see a redirect message each time a redirect occurs.This message can be customized from GeotargetingWP -> Settings -> Addons Settings, in the Geo Redirect section.

redirection-message

Placeholders

On the destination url field you can use multiple placeholders in order to create dynamic urls.

  • {{country_code}} Two letter iso code
  • {{state_code}} Two letter state code
  • {{zip}} Zip code
  • {{requested_uri}} Original requested url. Eg: http://geotargetingwp.com/geo-redirects
  • {{requested_path}} Original requested path. Eg: geo-redirects
Examples of dynamic urls

Let's assume that the origin url is http://domain.com/category/news/ , the country is United States and State florida. Some examples are:

/{{country_code}}/{{state_code}}/{{zip}}?path={{requested_path}}&url={{requested_uri}}

Will generate http://domain.com/us/fl/33166?path=category/news&url=http://domain.com/category/news/

{{requested_uri}}/{{country_code}}

Will generate http://domain.com/category/news/us

Filters

These are some of the filters available that will let you extend your redirects. All of them from addons "/geo-redirects/public/class-geotr-public.php".

  • 'geotr/remove_from_path': While we do have the option that removes two letter iso codes from {{requested_path}} it's possible that you have something else or with more that two letters. This filter accepts an array of string that will be removed from path.
  • 'geotr/placeholders': This filter will let you add your custom dynamic placeholders.
  • 'geotr/cancel_redirect': Boolean filter to cancel redirect.
  • 'geotr/final_url': Final destination url filter.

Check out our WordPress geolocation solutions
to find out everything you can do!

Start your free trial