Check HTTP cookie value with nginx using map directive – Server Fault
I need to perform a redirect depending on the client’s IP and the value that has been set in the cookie by WPML WordPress plugin.
I prefer to use the map directive for this purpose.
Excerpt of nginx.conf
geoip_country /usr/local/share/GeoIP/maxmind_countries.dat;
geoip_city /usr/local/share/GeoIP/maxmind_cities.dat;
map $host:$geoip_country_code:$cookie_wp-wpml_current_language $redirect {
"example.com:UA:''" "1";
"example.com:UA:'uk'" "0";
"example.com:UA:'ru'" "1";
Then in domain.conf I just check use $redirect in conditional statement
if ($redirect) {
return 301 https://example.com/uk;
}
So, my question is: how to check the value of a cookie the right way in general, and how to check if cookie is not set (has empty value) in particular using map directive for nginx?
Read more here: Source link