Last active
May 3, 2017 06:33
-
-
Save carlowens/ade2c85c5da4f601b54b52920fa93f93 to your computer and use it in GitHub Desktop.
nginx geoip redirect for magento 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###########START of redirect updates based on geoip######## | |
set $condition ''; | |
set $redirect_uri ''; | |
set $my_cookie ''; | |
if ($cookie_store) { | |
set $condition 'cookie'; | |
} | |
set $country 'none'; | |
if ($http_CF_IPCOUNTRY) { | |
set $country $http_CF_IPCOUNTRY; | |
set $condition "${condition}country"; | |
} | |
if ($country = 'SA') { | |
set $condition "${condition}KSA"; | |
} | |
if ($condition = 'cookiecountry') { | |
#has store cookie and a country | |
#just redirect to the cookie store if not already on it | |
set $cookie_redirect_condition $cookie_store; | |
} | |
if ($condition = 'cookie') { | |
#no country header sent so do nothing | |
#just redirect to store if not requesting it | |
set $cookie_redirect_condition $cookie_store; | |
} | |
if ($condition = 'country') { | |
#new visitor | |
set $my_cookie "store=uae_en;Domain=.$server_name;Max-Age=31536000"; | |
#redirect to store if not requesting it | |
set $redirect_uri '/ae-en/?___store=uae_en'; | |
} | |
if ($condition = 'countryKSA') { | |
#new visitor from KSA | |
set $my_cookie "store=ksa_ar;Domain=.$server_name;Max-Age=31536000"; | |
#redirect to store if not requesting it | |
set $redirect_uri '/sa-ar/?___store=ksa_ar'; | |
} | |
if ($cookie_store = 'uae_en') { | |
set $redirect_uri '/ae-en/?___store=uae_en'; | |
} | |
if ($cookie_store = 'uae_ar') { | |
set $redirect_uri '/ae-ar/?___store=uae_ar'; | |
} | |
if ($cookie_store = 'ksa_ar') { | |
set $redirect_uri '/sa-ar/?___store=ksa_ar'; | |
} | |
if ($cookie_store = 'ksa_en') { | |
set $redirect_uri '/sa-en/?___store=ksa_en'; | |
} | |
if ($cookie_store = 'nocom_ar') { | |
set $redirect_uri '/ar/?___store=nocom_ar'; | |
} | |
if ($cookie_store = 'nocom_en') { | |
set $redirect_uri '/?___store=nocom_en'; | |
} | |
#redirect conditions | |
set $redirect_condition ''; | |
if ($request_uri = '/') { | |
set $redirect_condition "${redirect_condition}isBase"; | |
} | |
if ($redirect_uri !~ $request_uri ) { | |
set $redirect_condition "${redirect_condition}NOTEQUAL"; | |
} | |
if ($redirect_uri != '') { | |
set $redirect_condition "${redirect_condition}HASREDIRECT"; | |
} | |
add_header Set-Cookie $my_cookie; | |
if ($redirect_condition = 'isBaseNOTEQUALHASREDIRECT') { | |
return 302 http://$server_name$redirect_uri; | |
} | |
###########END of redirect updates based on geoip######## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment