I’ve done quite a bit of reading on the subject:
And I can get things working individually (the country redirect and the proxy) but having trouble getting everything to work together with my environments.
The scenario is, we’ll have a main site that contains a homepage and subpages, /a
for example, which will cover users from countries that we aren’t managing sub-sites for. We then will have a series of sub sites for different countries and/or locations that we’ll proxy to a sub-folder (ie /en-au/
). These sub sites will also contain a homepage and potentially the same subpage urls.
/ /en-au/ 302 Country=au,nz
/en-au/* https://sub-site-au.netlify.app/:splat 200
This doesn’t automatically redirect the user in Australia because the main site managing the redirects contains a homepage, therefore matches and does not get to the redirect rule to force the user to /en-au/
, however, does work if you manually enter the url. So I force the 302:
/ /en-au/ 302! Country=au,nz
/en-au/* https://sub-site-au.netlify.app/:splat 200
This works to force users located in either Australia or New Zealand to the site URL /en-au/
for the homepage - great! But what if the user comes in at subpage /a
? It skips over these rules and stays on the main site. So you’d be forgiven in thinking that adding a splat to the country redirect would then work:
/* /en-au/:splat 302! Country=au,nz
/en-au/* https://sub-site-au.netlify.app/:splat 200
However, this doesn’t work. Even though the URL in the browser is maindomain.com/en-au/a
which is right, its returning a 404, where I would have expected this setup to proxy into that view the content on the URL of https://sub-site-au.netlify.app/a
. What it believe its doing is its hitting that prior 302 redirect and attempting /en-au/en-au/a
or even resulting in an infinite loop (technically) since its picking up the wildcard.
So - the question is, how do you force all paths for a user in a particular country to view a proxy without defining all the paths individually?