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:

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

Heya @Rivotti! Our team asserts that some changes from a few months ago should now NOT be causing all language redirects to behave as forced, so your original redirects should again work as you were thinking they would at first. Could you let us know if you try changing the config, how well it works?

Hi @fool. I did a quick test and it looks like it’s working as I originally expected :). I will try to implement my original project and give you additional feedback.
Nice work and many thanks.