Geoloc redirects not working in Net Dev

This is my first netlify community thread… :tada::smile:

First off, Netlify Dev is amazing!

Now it appears redirect rules per country (as in https://www.netlify.com/docs/redirects/#geoip-and-language-based-redirects) is not working in netlify dev.

I wonder if it’s a sensible limitation or a bug?

Thanks.

1 Like

The rules engine works, but we’re not shipping an IP geolocation database with Netlify dev, so we won’t detect the country based on IP. To test the rules you should be able to set an nf_country cookie with the 2 letter country code to simulate the country you want the engine to detect.

2 Likes

Hi Matt and thank you for your prompt answer!

It makes a lot of sense :slight_smile:

1 Like

Hey @biilmann, the nf_country cookie seems to be a great solution, but how do we instruct Netlify to add these cookies to response that’s not really a redirection (still respond with the same endpoint but adding these cookies to the response) ? The documentation is a bit unclear on this aspect where it says it’s possible but it doesn’t provide an example?

Cookies are normally created by site javascript or by using a Set-Cookie response header. You can also manually add cookies.

The suggestion above is about including the cookies yourself when testing the site with Netlify Dev. Netlify isn’t adding the cookies; you are doing so manually for testing.

I am not clear about why want to use Netlify to set this header for you. Would you be willing to please explain more about what goal you are trying to accomplish? Because I don’t currently understand the goal, I am unable to confidently give an answer.

You also wrote:

The documentation is a bit unclear on this aspect where it says it’s possible but it doesn’t provide an example?

What documentation are you referring to?

Thanks for your reply Luke.
I am referring to the same documentation listed on the original post.

Both the language and the country can be specified in a cookie as well ( nf_lang and nf_country respectively), so you can easily override the default behavior with JavaScript.

This gives the impression that I can get the country and language codes sent as a cookie in the response, but it doesn’t provide instructions on how to do so?

I have tried setting headers on netlify.toml redirects with the Set-Cookie which didn’t seem to work. It’s a bit unclear what nf_lang and nf_country are supposed to do here?

I hope that makes a bit more sense now.

1 Like

Hi,

nf_lang is a cookie that you yourself sets, we don’t set it for you. It tells our redirects engine which language to use for the redirect, and takes precedence over the Accpept-Language header that the browser sends. It’s the same situation with nf_country, which overrides our GeoIP lookup that we do for inbound requests for GeoIP redirects.