Country Redirects multiple netlify sites

Hello everyone,

I’ve just read through a few posts before posting and what I’m asking might not be possible but since I can’t figure it out, I might as well ask for some help !

We have a multi-country website to deploy, since all the slugs are admin-generated I can’t really use specific redirects.

I’m so glad country redirects are available since they perfectly fit my needs.

Thus I’m gonna have multiple deploys of my site

and so on…

All the deploys will only differ by an env variable which will trigger different content pages.
Therefore I thought I’d be able to build everything for the same branch (easier to maintain), but it seems like if I use my redirect like so

/* 302! Country=CA
/* 302! Country=US

I find myself in a redirect loop, indeed if I’m in the US, I’m redirecting to myself when on the foo-site-us.
Which seems to point me to the direction of having specific version of _redirects for each site, each excluding the redirect for the site I’m on.

Is there no way to have a single _redirect file (thus not needing to have multiple branches that I’ll have to keep in sync with future devevpment) ?

I hope I’m clear.
Cheers to you all, your product is truly amazing.

@Agiulian This is definitely possible because we had it working like this on a site back in 2017.

However we later removed it when we found that the google crawler (based in the US) wasn’t able to index the non-US sites.

I believe your loops issue is a combination of the from portion of your _redirects being a root relative wildcard and not a Domain Level Redirect, and the Country being a condition.

So you’re saying “If the user visiting this site is from the US redirect them to the US site”.
Which will work correctly when someone from the US site visits the CA site, but will also trigger when someone from the US site visits the US site.

Adding in domain level redirects our working rules from 2017 looked like:

# canada can see only the site* 302! Country=CA* 302! Country=CA
# united states can see only the site* 302! Country=US* 302! Country=US

1 Like

Thanks a lot, I somehow skipped this part of the redirect documentation.
It will indeed work with your solution.

Concerning your issue with the google crawler based in the us not being able to index the non-US sites :
If the goal is to prevent US users from being able to access the non US sites for legal reasons, it doesn’t seem to me that there’s a solution to allow only their crawler.
Or did you find one ?

Thanks a lot for your help !

If you’re okay with adding some server-side logic, you can use Netlify Edge Functions to check the user agent of Google’s crawlers. Edge Functions are evaluated before redirects.

Edge Functions were not available at the time, and we didn’t want to take the risk of being dinged for Cloaking.

We changed the approach from trying to auto-funnel the traffic and created a front-end based solution.

It detects the site visitors region, displays an alert if there is a “better site for them”, but ultimately leaves the decision of which region they view up to them.

More recently the site migrated from a subdomain based multi-region system, to a folder based multi-region system vs

Hello, website is finally live.

What I had set in place thanks to your advices and which was working on the websites doesn’t seem to work anymore though.

# united states can see only the site
https://****.com/* 302! Country=US
https://www.****.com/* 302! Country=US

# everywhere else can see only the site* 302! Country=...
https://****.us/* 302! Country=US
https://www.****.us/* https://www.****.com/:splat 302! Country=US

This seems to be the reason why, I have made 2 netlify websites one is hosting the .com the other the .us, all that’s different is an env variable.

Is there any way I can allow the redirect ?
Thanks in advance

Hey there, @Agiulian :wave:

It looks like your DNS is misconfigured for (you can see more here!) Can you please fix that configuration? Here are the instructions that are laid out in our docs.


1 Like

Thanks a lot, indeed I had a DNS problem and my redirections from the .us to the .com was flawed somehow. Need to get some sleep.
Best regards.

1 Like