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 https://site.com 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 site.com to point site.com/lang to the related site-lang.netlify.app.
/lang/* https://site-lang.netlify.app/:splat 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 https://site.com/lang
So I’d like to set up a redirect from
https://site-lang.netlify.app to https://site.com/lang
But this redirect should be based on the request origin to avoid loop redirects. I can’t just set :
https://site-lang.netlify.app https://site.com/lang 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:
> / https://site.com/lang/:splat 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:
/lang/* https://site-lang.netlify.app/:splat?secret=abc123 200
/* secret=abc123 /:splat 200
/* https://site.com/lang 301!
Fair warning, if it does work, I’m not sure how it’d handle