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

foo-site-us.netlify.app
foo-site-ca.netlify.app

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

/* foo-site-ca.netlify.app/:splat 302! Country=CA
/* foo-site-us.netlify.app/:splat 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 ca.website.com site
https://www.website.com/* https://ca.website.com/:splat 302! Country=CA
https://us.website.com/* https://ca.website.com/:splat 302! Country=CA
 
# united states can see only the us.website.com site
https://www.website.com/* https://us.website.com/:splat 302! Country=US
https://ca.website.com/* https://us.website.com/:splat 302! Country=US

# everywhere else can see only the www.website.com site
https://ca.website.com/* https://www.website.com/:splat 302! Country=AD,AE,AF,AG,AI,AL,AM,AO,AQ,AR,AS,AT,AU,AW,AX,AZ,BA,BB,BD,BE,BF,BG,BH,BI,BJ,BL,BM,BN,BO,BQ,BR,BS,BT,BV,BW,BY,BZ,CC,CD,CF,CG,CH,CI,CK,CL,CM,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KY,KZ,LA,LB,LC,LI,LK,LR,LS,LT,LU,LV,LY,MA,MC,MD,ME,MF,MG,MH,MK,ML,MM,MN,MO,MP,MQ,MR,MS,MT,MU,MV,MW,MX,MY,MZ,NA,NC,NE,NF,NG,NI,NL,NO,NP,NR,NU,NZ,OM,PA,PE,PF,PG,PH,PK,PL,PM,PN,PR,PS,PT,PW,PY,QA,RE,RO,RS,RU,RW,SA,SB,SC,SD,SE,SG,SH,SI,SJ,SK,SL,SM,SN,SO,SR,SS,ST,SV,SX,SY,SZ,TC,TD,TF,TG,TH,TJ,TK,TL,TM,TN,TO,TR,TT,TV,TW,TZ,UA,UG,UM,UY,UZ,VA,VC,VE,VG,VI,VN,VU,WF,WS,YE,YT,ZA,ZM,ZW
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 us.website.com vs website.com/us/

Hello, website is finally live.

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

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

# everywhere else can see only the www.website.com site
https://winback-webapp-us.netlify.app/* https://winback-webapp-com.netlify.app/:splat 302! Country=...
https://****.us/* https://winback.com/:splat 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 winback.us (you can see more here!) Can you please fix that configuration? Here are the instructions that are laid out in our docs.

Thanks!

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