User Tools

Site Tools


Sidebar

magento_2:geoip_redirect

For more details see how the GeoIP Redirect extension works.

Guide for GeoIP Redirect for Magento 2

Detect store visitors' location and automatically provide them with the appropriate store view, currency, and language. Move your business to the global level without creating additional stores.

  • Detect the location of your customers
  • Navigate visitors to appropriate store view or custom URL
  • Provide prices in local currencies
  • Automatically switch language for international shoppers
  • Exclude certain IP addresses from redirection
In GeoIP Redirect FAQ you can find answers to the most popular questions about the extension functionality.

Database Installation

To install the GeoIP Redirect database, go to Stores → Configuration → Amasty Extensions → GeoIP Data.

Databases are required for the correct work of the GeoIP Redirect module. Also you need to install php bcmath or gmp extension on your server.

You can get the databases automatically or import your own data.

Hit the Download and Import button to make the extension download the updated CSV dump file and import it into your database automatically.

To import the files from your own source, use the Import option. Path to the files should look like this (the part 'var/amasty' should be replaced with your folders’ names):

var/amasty/geoip/GeoLite2-City-Blocks-IPv4.csv 
var/amasty/geoip/GeoLite2-City-Blocks-IPv6.csv 
var/amasty/geoip/GeoLite2-City-Locations-en.csv
In the Import section, the Import button is grayed out by default. It will be available right after you upload the CSV files. The red error notification will switch to green success notification when the import is completed.

If you face any difficulties with importing the location database, please see the following solution.

General Extension Settings

To configure the GeoIP Redirect extension, go to Stores → Configuration → Amasty Extensions → GeoIP Redirect.

General

Enable GeoIP Redirect — Set to Yes to enable the extension.

Display Popup to Customers when Redirecting - set to Yes to display confirmation redirect pop-up to customers. The setting allows your website to be compliant with EU regulations regarding geo-blocking and country redirects.

Redirect Popup Type - choose Notification Popup just to inform customers about the redirection or Confirmation Popup if you want them to be allowed to decline redirection and stay at the initial website.

Confirmation Redirect Popup Text - specify the text that will be displayed to a customer on a pop-up before redirection happens.

Restriction

Apply Logic To — select the general logic of redirecting rules:

  • Specified URLs
  • All Except Specified URLs
  • Redirect From Home Page Only
The Specified URLs and All Except Specified URLs options let you to specify the URLs that should be allowed or disallowed.

Excepted URLs — choose the Specified URLs or All Except Specified URLs options above to define the excepted URLs here.

User Agents to Ignore — ignore redirection rules for specified search engines.

IP to Ignore — restrict redirection for certain IP addresses. Specify each IP on a separate line.

First Visit Redirect Only — activate to enable redirection only for the first visit.

Beware that if you set this option to No, customers wouldn’t be able to switch store view and currency at their desire.

Redirect Between Websites — enable to redirect visitors between several websites.

  • Yes - a customer will be redirected to the store view of a website from another website within your Magento (e.g. a customer tried to reach the default store view of the Website A, but was redirected to the store view 2 of the Website B).
  • No - a customer will be redirected to another store view only within one website. No redirection to magento 2 store view will occur if a customer reached another website of your Magento (e.g. a customer tried to reach the default store view of the Website A - success. A customer tried to reach the default store view of Website B and was redirected to the store view 2 of Website B).

Restriction by IP

IP to block - specify IP addresses you want to block.

CMS page to display - choose CMS page that will be displayed to the restricted customer.

Redirect within your Magento instance

Enable Country –> Store View — enable to redirect visitors from certain countries to particular store views.

When enabled, switch the Store View dropdown menu to the required version and define the list of countries that will be affected.

Country to Currency Switch

Enable Country –> Currency — set this option to Yes to automatically switch currency according to user’s location.

Country to Currency Mapping — define country — currency relation by selecting countries and the appropriate currencies. Hit the Add button to create a new relation.

Redirect to website outside your Magento instance

Enable Country –> URL — enable to redirect visitors from certain locations to any other URL.

Country to URL Mapping — select locations and specify the URL that would be used for redirection. Use the Add button to create a new country — URL relation.

If you enable the Use Website checkboxes for the mapping options, the same set of rules would be applied to the Main Website and the selected Store View.

Troubleshooting

GeoIP Data Import Failure

Sometimes, it is unable to complete the database import due to execution time limit of PHP scripts. You can avoid this error by increasing the maximum execution time for your PHP scripts.

You need to set the max_execution_time to the number of seconds that all your scripts are allowed to run in your PHP's configuration file. The file location may differ from system to system but in general you need to find the PHP.INI file and modify it.

We need to set the value to 18000.

For example:

; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 18000

Setting the value to 0 means there's no time limit.

You'll have to restart your web server for this solution to work.

Varnish Cache Compatibility

To make the redirect functionality work with Varnish Cache enabled, it is necessary to change just a few things in the web server configuration:

1. For nginx - add the following code in any place of the nginx.conf file:

set_real_ip_from <varnish-ip>;

2. For apache - add the following code in any place of the .htaccess file:

RemoteIPTrustedProxy <varnish-ip>;

Where <varnish-ip> is an IP address of the Varnish server.

You can contact a hosting provider to change the web server configuration or do it on your own. With an independent change, you need to have root access and restart the server after the changes are implemented.

FAQ

* Is the GeoIP Redirect module compatible with Varnish?

* How does the GeoIP Redirect module work with Cloudflare?

* Will the module work on Magento Cloud with Fastly?

* How often should I update the GeoIP Database?

* The module works inconsistently when tested with VPN. What could be the reason?

* Show more articles →


Find out how to install the GeoIP Redirect extension via Composer.

Rate the user guide
 stars  from 3 votes (Details)
magento_2/geoip_redirect.txt · Last modified: 2023/05/18 14:07 by kkondrateva