{"id":5235,"date":"2020-07-23T13:47:33","date_gmt":"2020-07-23T08:17:33","guid":{"rendered":"https:\/\/www.skynats.com\/?p=5235"},"modified":"2024-10-28T12:48:25","modified_gmt":"2024-10-28T07:18:25","slug":"country-based-redirection-in-magento-using-geoip","status":"publish","type":"post","link":"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/","title":{"rendered":"Country Based Redirection In Magento using GeoIP"},"content":{"rendered":"\n<p>The GeoIP module is used to find which Geolocation or area is used by the IP from IP location database. We can setup country based redirection rule in htaccess for Magento2 which will redirect the required stores to the specific countries.<br>To add rules for country based redirection in Magento we have to install the GeoIP module. <\/p>\n\n\n\n<p>The below installation needs to be done on a centos 7 server and if you need this to be done from our end or need help to setup on any other OS, Click <a aria-label=\"undefined (opens in a new tab)\" href=\"https:\/\/www.skynats.com\/contact-us\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>here<\/strong><\/a> to contact our experts to get it done right now.<\/p>\n\n\n\n<p><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">Install GeoIP and dependencies<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum install GeoIP GeoIP-devel GeoIP-data zlib-devel<\/code><\/pre>\n\n\n\n<p>Change the directory to the \/usr\/share\/GeoIP\/, upload and extract GeoIP database in this location<br>You can download the GeoIP database from <a href=\"https:\/\/dev.maxmind.com\/geoip\/geoip2\/geolite2\/\">https:\/\/dev.maxmind.com\/geoip\/<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/usr\/share\/GeoIP\/\ntar -xzvf GeoLite2-ASN_20200630.tar.gz<\/code><\/pre>\n\n\n\n<p><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">Install the required packages for GeoIP<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum install httpd-devel apr-devel ea-apache24-devel.x86_64 ea-apache24-tools.x86_64<\/code><\/pre>\n\n\n\n<p><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">&nbsp;Download and extract GeoIP module using the below steps<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/github.com\/maxmind\/geoip-api-mod_geoip2\/archive\/1.2.10.tar.gz\ntar -xzvf 1.2.10.tar.gz\ncd mod_geoip2_1.2.10\nsed s\/remote_ip\/client_ip\/g -i mod_geoip.c<\/code><\/pre>\n\n\n\n<p><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">Compile and install the GeoIP module<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apxs -i -a -L\/usr\/lib64 -I\/usr\/include -lGeoIP -c mod_geoip.c<\/code><\/pre>\n\n\n\n<p><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">Load the module in Apache at Apache modules conf.<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/apache2\/conf.modules.d\/mod_geoip.conf\n\n###########\nLoadModule geoip_module \/usr\/lib64\/apache2\/modules\/mod_geoip.so\n\n&lt;IfModule mod_geoip.c&gt;\nGeoIPEnable On\nGeoIPScanProxyHeaders On\nGeoIPDBFile \/usr\/share\/GeoIP\/GeoIPASNum.dat Standard\nGeoIPDBFile \/usr\/share\/GeoIP\/GeoIPCity.dat Standard\n&lt;\/IfModule&gt;\n###########<\/code><\/pre>\n\n\n\n<p><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">Check Apache Configuration and restart Apache<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>httpd -t\nservice httpd restart<\/code><\/pre>\n\n\n\n<p><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">Verify if GeoIP module is enabled by<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>httpd -M | grep geoip<\/code><\/pre>\n\n\n\n<p>Next, we have to add the rule for redirection of countrywide access in Magento2 site. There are certain country codes available for GeoIP database. We can use that country codes here to add rules in .htaccess.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;IfModule mod_rewrite.c&gt;\nRewriteEngine on\nRewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(GB|RU|IN)$\nRewriteCond %{REQUEST_URI} !^\/store\/\nRewriteRule .* https:\/\/www.example.com\/store\/ &#91;L]\n&lt;\/IfModule&gt;\n\nwhere GB|RU|IN are the country codes for UK, Russia and India<\/code><\/pre>\n\n\n\n<p><strong><span class=\"has-inline-color has-vivid-cyan-blue-color\">Restart Apache<\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>service httpd restart<\/code><\/pre>\n\n\n\n<p>According to the above rule, the users accessing from UK and Russia and India for \/store of https:\/\/www.example.com, will redirect to https:\/\/www.example.com\/store.<br>By using GeoIP module we can also block and deny countrywide access to the site.<\/p>\n\n\n\n<figure class=\"wp-block-pullquote is-style-default has-vivid-red-color has-text-color\"><blockquote><p><strong>Are you struggling with managing your server?<\/strong><\/p><cite><em><strong><a href=\"https:\/\/www.skynats.com\/cpanel-server-management\/\" target=\"_blank\" aria-label=\"undefined (opens in a new tab)\" rel=\"noreferrer noopener\">check our management plans here<\/a><\/strong><\/em><\/cite><\/blockquote><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>The GeoIP module is used to find which Geolocation or area is used by the IP from IP location database. We can setup country based redirection rule in htaccess for Magento2 which will redirect the required stores to the specific countries.To add rules for country based redirection in Magento we have to install the GeoIP [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,68],"tags":[42,91,92,35,93,94,18,95,96,97,98,99,100,72,22],"class_list":["post-5235","post","type-post","status-publish","format-standard","hentry","category-blog","category-server-management","tag-apache","tag-apache-country-block","tag-apache-redirection","tag-apache-webserver","tag-apache-website","tag-countrybased-redirection","tag-cpanel","tag-htaccess-redirects","tag-htaccess-rules","tag-magento","tag-magento-county-block","tag-magento-redirects","tag-magento2","tag-server-management","tag-server-support"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Country Based Redirection In Magento using GeoIP | Skynats<\/title>\n<meta name=\"description\" content=\"Are you struggling to setup country based redirection in magento website? Please readb this topic and contact us to get id done right now!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Country Based Redirection In Magento using GeoIP\" \/>\n<meta property=\"og:description\" content=\"Are you struggling to setup country based redirection in magento website? Please readb this topic and contact us to get id done right now!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/\" \/>\n<meta property=\"og:site_name\" content=\"Server Management Services | Cloud Management | Skynats\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/skynats\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-23T08:17:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-28T07:18:25+00:00\" \/>\n<meta name=\"author\" content=\"Tony\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@skynatstech\" \/>\n<meta name=\"twitter:site\" content=\"@skynatstech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tony\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/country-based-redirection-in-magento-using-geoip\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/country-based-redirection-in-magento-using-geoip\\\/\"},\"author\":{\"name\":\"Tony\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/person\\\/1398d4641035daa52ed8b827e0aafdeb\"},\"headline\":\"Country Based Redirection In Magento using GeoIP\",\"datePublished\":\"2020-07-23T08:17:33+00:00\",\"dateModified\":\"2024-10-28T07:18:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/country-based-redirection-in-magento-using-geoip\\\/\"},\"wordCount\":276,\"publisher\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#organization\"},\"keywords\":[\"apache\",\"apache country block\",\"apache redirection\",\"apache webserver\",\"apache website\",\"countrybased redirection\",\"cpanel\",\"htaccess redirects\",\"htaccess rules\",\"magento\",\"magento county block\",\"magento redirects\",\"magento2\",\"server management\",\"server support\"],\"articleSection\":[\"Blog\",\"server management\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/country-based-redirection-in-magento-using-geoip\\\/\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/country-based-redirection-in-magento-using-geoip\\\/\",\"name\":\"Country Based Redirection In Magento using GeoIP | Skynats\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#website\"},\"datePublished\":\"2020-07-23T08:17:33+00:00\",\"dateModified\":\"2024-10-28T07:18:25+00:00\",\"description\":\"Are you struggling to setup country based redirection in magento website? Please readb this topic and contact us to get id done right now!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/country-based-redirection-in-magento-using-geoip\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.skynats.com\\\/blog\\\/country-based-redirection-in-magento-using-geoip\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/country-based-redirection-in-magento-using-geoip\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Country Based Redirection In Magento using GeoIP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/\",\"name\":\"Server Management Services | Cloud Management | Skynats\",\"description\":\"Server Management and Cloud Management\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#organization\",\"name\":\"Skynats Technologies\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/Sknats-Logo-New-whole.png\",\"contentUrl\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/08\\\/Sknats-Logo-New-whole.png\",\"width\":989,\"height\":367,\"caption\":\"Skynats Technologies\"},\"image\":{\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/skynats\",\"https:\\\/\\\/x.com\\\/skynatstech\",\"https:\\\/\\\/www.instagram.com\\\/skynatstech\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/skynats-technologies\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCvTAjrFJ4_E2MJKwlDHomlg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.skynats.com\\\/blog\\\/#\\\/schema\\\/person\\\/1398d4641035daa52ed8b827e0aafdeb\",\"name\":\"Tony\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f90e801961478d690f50507d9e19eeecebabab8ab7dfdab7d2d2431114c6acd9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f90e801961478d690f50507d9e19eeecebabab8ab7dfdab7d2d2431114c6acd9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f90e801961478d690f50507d9e19eeecebabab8ab7dfdab7d2d2431114c6acd9?s=96&d=mm&r=g\",\"caption\":\"Tony\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Country Based Redirection In Magento using GeoIP | Skynats","description":"Are you struggling to setup country based redirection in magento website? Please readb this topic and contact us to get id done right now!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/","og_locale":"en_US","og_type":"article","og_title":"Country Based Redirection In Magento using GeoIP","og_description":"Are you struggling to setup country based redirection in magento website? Please readb this topic and contact us to get id done right now!","og_url":"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/","og_site_name":"Server Management Services | Cloud Management | Skynats","article_publisher":"https:\/\/www.facebook.com\/skynats","article_published_time":"2020-07-23T08:17:33+00:00","article_modified_time":"2024-10-28T07:18:25+00:00","author":"Tony","twitter_card":"summary_large_image","twitter_creator":"@skynatstech","twitter_site":"@skynatstech","twitter_misc":{"Written by":"Tony","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/#article","isPartOf":{"@id":"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/"},"author":{"name":"Tony","@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/person\/1398d4641035daa52ed8b827e0aafdeb"},"headline":"Country Based Redirection In Magento using GeoIP","datePublished":"2020-07-23T08:17:33+00:00","dateModified":"2024-10-28T07:18:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/"},"wordCount":276,"publisher":{"@id":"https:\/\/www.skynats.com\/blog\/#organization"},"keywords":["apache","apache country block","apache redirection","apache webserver","apache website","countrybased redirection","cpanel","htaccess redirects","htaccess rules","magento","magento county block","magento redirects","magento2","server management","server support"],"articleSection":["Blog","server management"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/","url":"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/","name":"Country Based Redirection In Magento using GeoIP | Skynats","isPartOf":{"@id":"https:\/\/www.skynats.com\/blog\/#website"},"datePublished":"2020-07-23T08:17:33+00:00","dateModified":"2024-10-28T07:18:25+00:00","description":"Are you struggling to setup country based redirection in magento website? Please readb this topic and contact us to get id done right now!","breadcrumb":{"@id":"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.skynats.com\/blog\/country-based-redirection-in-magento-using-geoip\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.skynats.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Country Based Redirection In Magento using GeoIP"}]},{"@type":"WebSite","@id":"https:\/\/www.skynats.com\/blog\/#website","url":"https:\/\/www.skynats.com\/blog\/","name":"Server Management Services | Cloud Management | Skynats","description":"Server Management and Cloud Management","publisher":{"@id":"https:\/\/www.skynats.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.skynats.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.skynats.com\/blog\/#organization","name":"Skynats Technologies","url":"https:\/\/www.skynats.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.skynats.com\/blog\/wp-content\/uploads\/2021\/08\/Sknats-Logo-New-whole.png","contentUrl":"https:\/\/www.skynats.com\/blog\/wp-content\/uploads\/2021\/08\/Sknats-Logo-New-whole.png","width":989,"height":367,"caption":"Skynats Technologies"},"image":{"@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/skynats","https:\/\/x.com\/skynatstech","https:\/\/www.instagram.com\/skynatstech\/","https:\/\/www.linkedin.com\/company\/skynats-technologies","https:\/\/www.youtube.com\/channel\/UCvTAjrFJ4_E2MJKwlDHomlg"]},{"@type":"Person","@id":"https:\/\/www.skynats.com\/blog\/#\/schema\/person\/1398d4641035daa52ed8b827e0aafdeb","name":"Tony","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f90e801961478d690f50507d9e19eeecebabab8ab7dfdab7d2d2431114c6acd9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f90e801961478d690f50507d9e19eeecebabab8ab7dfdab7d2d2431114c6acd9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f90e801961478d690f50507d9e19eeecebabab8ab7dfdab7d2d2431114c6acd9?s=96&d=mm&r=g","caption":"Tony"}}]}},"_links":{"self":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/5235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/comments?post=5235"}],"version-history":[{"count":0,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/5235\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/media?parent=5235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/categories?post=5235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/tags?post=5235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}