Magento Store switcher redirects based on HTTP header named “CF-IPCountry”

Posted by - Vasanth Kalyan at Jun 23, 2022
Oaxaca, Mexico

BudgetTypeStatusValid Through
$146.98FIXEDOpenJul 14, 2022

Job Description

We need our Magento web store to switch stores based on CF_IPCOUNTRY which is passed into the HTTP header by Cloudflare

The way we are setup is the store ID is added to the web url

For example:

domain.com/us-en
domain.com/ca-en
domain.com/eu-en

Either this should be done in .htaccess, or PHP code in the header.

In this case it is important that only the store is switched, and no js, css or image files.

So the htaccess file needs to be setup as follows.

If country is USA - send visitor to domain.com/us-en/* (append full url)
If country is X (we will need to provide a list of country names) send visitor to domain.com/eu-en
Else, send visitor to domain.com/ca-en

We should also have the ability to exclude an IP address from this so that we can test locally.
It should also be ignored by robots and spiders.

We also tried with PHP code in the header, but this did not work. Maybe there is a different way?

<?php

$country_code = $_SERVER ['HTTP_CF_IPCOUNTRY'];

if ($country_code=='US') {
$link = '//domain.com/us/';
}
else if ($country_code=='GB') {
$link = '//domain.com/eu/';
}
else if ($country_code=='DE') {
$link = '//domain.com/eu/';
}

else {
$link = '//domain.com/us/';
}

header('location:$link');
exit;
?>

Note that I will not be giving server access. I just need the code which I can upload myself. We also plan to edit ourselves when we need to add more countries to redirect.

I will pay a 50% bonus if this is solved today.

Skills & Expertise Required

Magento 2 Website Development 

Offer to work on this project closes in 14 days!

Try more jobs by Vasanth Kalyan

American Speaking Voice Over for Natural Remedies Video - Fixed
Front-end Dev for Web & Mobile App - Hourly
Data science/machine learning/deep learning work - Hourly
Google Maps count traveled state miles - Fixed
ifix how OPC server. DCOM - Hourly

Similar Projects

ROM development

Hello,

I have a few STB's and I need some customization complete.

Eg.

1. I need default clock changed from 24-hour to AM/PM.
2. I need to modify the power intent in Se...read more
Fixed, $73.49

SEO Expert needed to fix website is...

Hello,

I am making a website and don't have a lot of time to put into it. I have the basic framework up and running. I am in need of someone who can fix the problems i will share a documents...read more
Fixed, $73.49

Mobile Development

Hello,

I am looking for an Android and Iphone application developer for a new project that I intend to launch beginning of March 2019.

The idea is very simple but needs some serious...read more
Hourly, $13.23

Vasanth Kalyan hiring Magento 2, Website Development experts from & nearby:

  • Afghanistan
  • Albania
  • Algeria
  • American Samoa
  • Andorra
  • Angola
  • Anguilla
  • Antarctica
  • Antiguaand Barbuda
  • Argentina
  • Armenia
  • Aruba
  • Australia
  • Austria
  • Azerbaijan
  • Bahamas
  • Bahrain
  • Bangladesh
  • Barbados
  • Belarus
  • Belgium
  • Belize
  • Benin
  • Bermuda
  • Bhutan
  • Bolivia
  • Bosniaand Herzegovina
  • Botswana
  • Bouvet Island
  • Brazil
  • British Indian Ocean Territory
  • Brunei
  • Bulgaria
  • Burkina Faso
  • Burundi
  • Cambodia
  • Cameroon
  • Canada
  • Cape Verde
  • Cayman Islands
  • Central African Republic
  • Chad
  • Chile
  • China
  • Christmas Island
  • Cocos Islands
  • Colombia
  • Comoros
  • Republic of the Congo
  • Democratic Republicof the Congo
  • Cook Islands
  • Costa Rica
  • Ivory Coast
  • Croatia
  • Cuba
  • Cyprus
  • Czech Republic
  • Denmark
  • Djibouti
  • Dominica
  • Dominican Republic
  • EastTimor
  • Ecuador
  • Egypt
  • El Salvador
  • Equatorial Guinea
  • Eritrea
  • Estonia
  • Ethiopia
  • External Territories of Australia
  • Falkland Islands
  • Faroe Islands
  • Fiji
  • Finland
  • France
  • French Guiana
  • French Polynesia
  • French Southern Territories
  • Gabon
  • Gambia
  • Georgia
  • Germany
  • Ghana
  • Gibraltar
  • Greece
  • Greenland
  • Grenada
  • Guadeloupe
  • Guam
  • Guatemala
  • Guernseyand Alderney
  • Guinea
  • Guinea-Bissau
  • Guyana
  • Haiti
  • Heard Islandand McDonald Islands
  • Honduras
  • HongKong
  • Hungary
  • Iceland
  • India
  • Indonesia
  • Iran
  • Iraq
  • Ireland
  • Israel
  • Italy
  • Jamaica
  • Japan
  • Jersey
  • Jordan
  • Kazakhstan
  • Kenya
  • Kiribati
  • North Korea
  • South Korea
  • Kuwait
  • Kyrgyzstan
  • Laos
  • Latvia
  • Lebanon
  • Lesotho
  • Liberia
  • Libya
  • Liechtenstein
  • Lithuania
  • Luxembourg
  • Macao
  • Macedonia
  • Madagascar
  • Malawi
  • Malaysia
  • Maldives
  • Mali
  • Malta
  • Man(Isleof)
  • Marshall Islands
  • Martinique
  • Mauritania
  • Mauritius
  • Mayotte
  • Mexico
  • Micronesia
  • Moldova
  • Monaco
  • Mongolia
  • Montserrat
  • Morocco
  • Mozambique
  • Myanmar
  • Namibia
  • Nauru
  • Nepal
  • Netherlands Antilles
  • Netherlands
  • New Caledonia
  • New Zealand
  • Nicaragua
  • Niger
  • Nigeria
  • Niue
  • Norfolk Island
  • Northern Mariana Islands
  • Norway
  • Oman
  • Pakistan
  • Palau
  • Palestinian Territory
  • Panama
  • Papua New Guinea
  • Paraguay
  • Peru
  • Philippines
  • Pitcairn
  • Poland
  • Portugal
  • Puerto Rico
  • Qatar
  • Reunion
  • Romania
  • Russia
  • Rwanda
  • Saint Helena
  • Saint Kittsand Nevis
  • Saint Lucia
  • Saint Pierreand Miquelon
  • Saint Vincentandthe Grenadines
  • Samoa
  • San Marino
  • Sao Tomeand Principe
  • Saudi Arabia
  • Senegal
  • Serbia
  • Seychelles
  • SierraLeone
  • Singapore
  • Slovakia
  • Slovenia
  • Smaller Territories of the UK
  • Solomon Islands
  • Somalia
  • South Africa
  • South Georgia and the South Sandwich Islands
  • South Sudan
  • Spain
  • Sri Lanka
  • Sudan
  • Suriname
  • Svalbardand Jan Mayen
  • Swaziland
  • Sweden
  • Switzerland
  • Syria
  • Taiwan
  • Tajikistan
  • Tanzania
  • Thailand
  • Togo
  • Tokelau
  • Tonga
  • Trinidadand Tobago
  • Tunisia
  • Turkey
  • Turkmenistan
  • Turksand Caicos Islands
  • Tuvalu
  • Uganda
  • Ukraine
  • United Arab Emirates
  • United Kingdom
  • United States
  • United States Minor Outlying Islands
  • Uruguay
  • Uzbekistan
  • Vanuatu
  • Vatican
  • Venezuela
  • Vietnam
  • British Virgin Islands
  • U.S.Virgin Islands
  • Wallis and Futuna
  • Western Sahara
  • Yemen
  • Yugoslavia
  • Zambia
  • Zimbabwe
  • Aland Islands
  • Saint Barthélemy
  • Bonaire, Saint Eustatiusand Saba
  • Curaçao
  • Guernsey
  • Isleof Man
  • Jersey
  • Montenegro
  • Saint Martin
  • Sint Maarten
  • East Timor
  • Kosovo