Country and Mobile Redirect for WordPress – Tutorial

Redirect to Country specific website

Below is the an example of how to use plugin for redirect all users from United kingdom to Amazon United Kingdom site (http://www.amazon.co.uk/)

i.e Redirection from  http://www.amazon.com to http://www.amazon.co.uk/ for United Kingdom users.

Click on Redirect Rules from left menu or from Dashboard. Redirect Rules list page will be displayed as shown below. Click on + Redirect Rule button, Add Redirect Page will be displayed.

Redirect_add_rule

Provide appropriate values for below fields.

Rule Name : Redirect Rule name and should be unique.
ex.UK Amazon Site Redirect.

Description : Appropriate description for your rule.

Redirect Type : 301 or 302.

Status : This feature is useful if you would like to deactivate or activate rule.

Target URL : URL to which you want to redirect
ex : In our sample use case it is http://www.amazon.co.uk/

Add Rule : Plugin provides three different ways of Adding Rule.

  • Standard Rule: Used to define standard rules like.
    • Country = UK and Page = Home.
    • User Role = Administrator and Country = INDIA and Date less than 05-01-2016 etc.

     

  • Advanced Rule : Advance rule is one of the key features of RulesEngine Platform. RulesEngine is very flexible for defining very complex logical rules using “AND” “OR” and “Brackets” operators.Example: Advanced Rule is used to redirect to http://rulesengine if the users from Washington or Sidney Cities or from India and date is less than Jan 01, 2017.
  • Use Existing Rule: Used for choosing an existing rule.

Add Criteria : Used to define on what condition/criteria we want to direct. In our sample, we would like to redirect if the user is from United Kingdom and accessing home page.

We can define a logical rule using 33 categories like User Role, Geo location, Date and Time etc Click here to view the list of categories and sub-categories for defining the rule.

So the rule is defined using Geo location criteria and Page is Home Page. Click on images to view in full screen.

After defining the Logical Rule, click on Save Rule. This will create a Redirect Rule and list the rule details as shown below.

Amazon_rule_list

Redirect to Mobile website

Below is the an example of how to use plugin for redirect all mobile users to a mobile banking site. Example :

i.e Redirection from  https://www.hdfcbank.com to https://m.hdfcbank.com/ mobile site.

Click on Redirect Rules from left menu or from Dashboard. Redirect Rules list page will be displayed as shown below. Click on + Redirect Rule button, Add Redirect Page will be displayed.

Redirect_add_rule

Provide appropriate values for below fields.

Rule Name : Redirect Rule name and should be unique.
ex. HDFC Bank Mobile Redirect

Description : Appropriate description for your rule.

Redirect Type : 301 or 302.

Status : This feature is useful if you would like to deactivate or activate rule.

Target URL : URL to which you want to redirect
ex : In our sample use case it is https://m.hdfcbank.com/

Add Rule: Used to define on what condition/criteria we want to direct. In our sample, we would like to redirect for mobile user accessing home page.

Action Hook : Hook will be invoked if the rule satisfied, useful for developers. (Not a mandatory field)

So the rule is defined using Mobile device criteria and Page is Home Page. Click on the image to view the rule.

After defining the, click on Save Rule. This will create a Redirect Rule and list the rule details as shown below.

HDFCBankMobileList

 

Redirect using Country Dropdown

Below is the an example of how to use plugin for redirecting users to a country specific website using the country dropdown shortcode.
Demo of country dropdown is available on top right corner of the Page. Page will be redirected to amazon website of selected country. Similarly customer can configure the their website URLs.

Here we take an use-case of redirect to Amazon India website https://www.amazon.in/ on selecting the india from dropdown.

To use country dropdown we should add the dropdown shortcode at the required place and then create a Redirect Rule based on the dropdown value.

How to Add Country dropdown: Login to your website admin console, click on dashboard and from left menu select Appearances and click on Editor.

Edit Theme page will be opened, click on the header.php add below line.


Add after :– Edit Theme page will be opened, click on the header.php add below line.

<?php echo do_shortcode('[bis_country_selector]'); ?>

Below are different option available with country dropdown.

  • [bis_country_selector] : Default usage to generate country drop down.
  • [bis_country_selector include="IN,US" ] : Generate country drop down with only India and US countries.
  • [bis_country_selector exclude="IN, US" ] : Generate country drop down excluding only India and US countries.
  • [bis_country_selector exclude="IN,US" eng_label="true" ] : Generate country drop down excluding only India and US countries and drop down with English labels. eng_label can have true, false and only option and default value is false.
  • [bis_country_selector exclude="IN,US" class=”custom-css” ] : Generate country dropdown excluding only India and US countries with custom dropdown class.

Creating Redirect Rule

Click on Redirect Rules from left menu or from Dashboard. Redirect Rules list page will be displayed as shown below. Click on + Redirect Rule button, Add Redirect Page will be displayed.

Redirect_add_rule

Provide appropriate values for below fields.

Rule Name : Redirect Rule name and should be unique.
ex. India Amazon Site Redirect

Description : Appropriate description for your rule.

Redirect Type : 301 or 302.

Status : This feature is useful if you would like to deactivate or activate rule.

Target URL : URL to which you want to redirect
ex : In our sample use case it is https://www.amazon.in/

Add Rule : Used to define on what condition/criteria we want to direct. In our sample, we would like to redirect for india website on changing the dropdown.

So the rule is defined using Request Criteria and with Form Data as Sub category and value should be the bis_country=IN(Where IN is ISO country code of India). Similarly if you would like to define for France value will be bis_country=FR.
US value will be bis_country=US.

These are universal standard ISO country codes. Click here for country codes

To persist the user select country update the rule with cookie value as shown in the below screen. For all new requests user selected country will be used and user will be redirected country specific website.

This is how we can define redirection rules, if you need more info send mail to rules4wp@gmail.com. I can provide more samples.

Installing Cities Database:

This plugin comes with the MaxMind Countries database. Customers can configure the Cities database also with plugin, which works for both cities and countries. To configure cities database download the Maxind Cities database from the Maxmin website.

Click here to download OpenSource MaxMind Cities Database

Download the extract the file GeoLite2 City MaxMind DB binary, gzipped file. The zip contains “GeoLite2-City.mmdb” file. Copy the “GeoLite2-City.mmdb” to the below location.

Example:

<WordPress Installation directory>\wp-content\uploads\bis_rulesengine_uploads

Example:

C:\xampp\htdocs\wordpress451\wp-content\wp-content\uploads\bis_rulesengine_uploads

IP2Location Database:

Download the extract the file IP2LOCATION-LITE-DB11.BIN File IP2LOCATIONDB binary, gzipped file. The zip contains “IP2LOCATION-LITE-DB11.BIN” file. Copy the “IP2LOCATION-LITE-DB11.BIN” to the below location.

Example:

<WordPress Installation directory>\wp-content\uploads\bis_rulesengine_uploads

Example:

C:\xampp\htdocs\wordpress451\wp-content\wp-content\uploads\bis_rulesengine_uploads

From WordPress Admin dashboard go to RulesEngine Plugin Settings Page. Setting page will be displayed as shown below. Enter the file name “GeoLite2-City.mmdb” in the Use MaxMind database table and click on the Save Settings button as shown below.

GeoCityDBConfig

 

Redirect from Mobile to Desktop Site

Sometime user might be interested in switching back to desktop site from mobile site for some extra features. In such scenarios use an “bis_nrd=1” , which is interpreted by server as no redirect and this is valid for this current session. Example.

http://rulesengine.in?bis_nrd=1

To reapply the redirect, use “bis_nrd=0”, using this feature, we can enable and disable redirection for current session

How to Overcome from Bad Redirect Rule

Sometimes by mistakenly, admin might have create a bad rule, which might have resulted in a redirect loop. To overcome redirect loop, use parameter “bis_nrd=1”.

Example:
http://rulesengine.in?bis_nrd=1

This parameter will be interpreted by plugin and stops the redirection, so that admin can login and remove/deactivate bad redirection rule.