Combining SPA redirect with Language condition

I want to create a single page app but with a twist: deliver a pre-built html based on Language.
After reading the docs, I came up with this _redirects file:

/* /pt.html 200 Language=pt
/* /en.html 200

It kind of works… let me explain.
My browsers default language is ‘pt’ and when I get to the page it delivers the pt.html content but, if I try to get /main.css it also gives me pt.html content. If I create a “vf_lang” cookie, /main.css renders the corresponding existing file.

Maybe I’m having the wrong approach here but regardless, it seems that, having Language condition breaks the default behavior regarding existing files.

You can test this behaviour in:
https://admiring-wing-6e1285.netlify.com

Hi @Rivotti,

That rule won’t work as you intend it. Language and country based redirects work as though you have forced = true. Usually they are used with 301 or 302 redirects rather than 200 proxy rules. Currently there isn’t a way to do what you are trying with combining a language based redirect with an SPA redirect. We have an open issue to see if we can adjust this behavior. We’ll let you know when it changes (which likely won’t be for at least a few months).

One alternative would be to put your different language files in different directories and split that your rule in to two different rules like this:

/pt/* /pt/index.html 200
/* /pt/:splat 302! Language=pt

I didn’t test that but I believe it’ll do what you are trying to do. It just requires that you use a sub-directory for the pt language rather than a different file.

Thanks for the reply @futuregerald. I’ve seen this in the docs but was hoping to avoid it since what I really wanted was to have a single entry point. Looking forward to any updates on this. Meanwhile I’ll use the alternative you gave me, thanks.

1 Like