Redirect based on origin, or browser url for multilingual website


I’m building a static multilingual website, using the proxy strategy explained here :

Each lang has it’s own site generated on netlify (same repo, different env var)
I have one on netlify, wich is the default language, with my custom domain pointing to it.
And all the other langs has their own netlify name :

I use proxy rules on the main to point to the related
/lang/* 200

Everything works fine.

But now, I don’t want the “netlify app” url to be accessed directly, I want it to be only accessible at
So I’d like to set up a redirect from to

But this redirect should be based on the request origin to avoid loop redirects. I can’t just set : 301!
=> Too many redirects

Is there a way to do that with netlify redirects ?
Or is there a better way to handle that ?

Thanks a lot for your help !

Can you amend the redirect to:

> / 301! Country=:country

Then make sure your that redirect only occurs if the request does not originate from your custom domain. Finally, it would be helpful for us and other community members if you could share your repo?

Thanks for your answer, althought I’m not sure I understand it correctly.
I don’t really want the country based auto redirect, and as I see it this would still be a loop redirect as I don’t know how to make sure this redirect don’t occur on my custom domain.

I can’t share my repo as it’s my client’s, but I’d be happy to help or share specific details on how we handled things.

@vdilly The redirects system is fairly limited in its capabilities, so for more complex use-cases you can use Edge Functions.

I’ve not tried this myself so it probably doesn’t work, but thinking on possible solutions with features I can see in the documentation for redirects, would it be possible for your proxy to pass an additional parameter that you could key off?

Something along the lines of:

Main Site

/lang/* 200

Sub Site

/* secret=abc123 /:splat 200
/* 301!

Fair warning, if it does work, I’m not sure how it’d handle 404’s