After my recent upgrade vom kirby2 to kirby3 I noticed, that my language detection does not work anymore.
In my kirby2 site I had the url param for the default language german set to /.
According to the issue https://github.com/getkirby/kirby/issues/1924 this does not work anymore in kirby3 and I had to set it to null or /de. After applying this change, the language detection works perfectly smooth again.
Now I would like to assure, that the old urlâs are redirected correctly. I tried to apply some stuff in the .htaccess, but could not make it work. I mostly ended up with too many redirects.
Is there an effective way to do this via routes? Or do I have to apply all the redirects manually?
My goal is that all urlâs without a language param redirect to the equivalent of the request with the de param. However, requests with en, fr and it should not be influenced by this.
Hm, these redirects should actually happen automatically. If you enter a url without the language parameter, it will automatically redirect to the URL with the default language parameter.
Sorry for the late reply. I think the problem is that your rewrite rule interferes with Kirbys builtin routes which will be applied when having a multilang setup. Your problem seems only occur with URLs that does not contain the language value and should therefore be redirected to /de/⌠- if I get it right. However you can not just rewrite everything which does not contain the language code to an URL with the language code as this will disturb Kirbys internal mechanism to sort things out. So far as I can tell you have at least 3 options to solve this:
Make Kirby believe that you do not have a multilang setup and rebuild all necessary routes with rewrite rules by yourself. Honestly I do not think that this is the best solution or even a good solution at all as you need a deep understanding of Kirbys internals and it requires a lot of caretaking.
If it is correct what can be derived from you description above and you have only URLs that start with the string âsubsiteâ then you could try to only rewrite all URLs of kind â/subsite/â to â/de/subsite/â which should also be possible with âRedirectâ (or âRedirectMatchâ) configuration directives and which is the recommended way in that case as far I remember from the Apache docs.
I inspected the Kirby source code and found that the default status code 302 is hard-coded in kirby/src/Cms/responder.php with an option to change it with a parameter to the redirect method:
The LanguageRoutes.php however, where all the redirects being created for multilang setup, does not make use of this parameter. Since there seems to be also no configuration option for changing the default value 302 into 301, you could change it in the file mentioned above, which of course is a dirty hack.
Saying that, I have to admit that I do not know enough about the internals of Kirby and the reasons which led to the default status code of 302 being hard-coded in the file mentioned above. Maybe it is possible to change that to a configurable setting or maybe it is possible to change this in a more compatible way - which is a question to the Kirby developers around here.
The reason behind making 302 the default redirect is that 301 redirects are cached by browsers. Since you cannot influence this on the client side, 301 redirects may have unwanted side effects if you ever decide you want to use those redirected URLs again.