user3311313
user3311313

Reputation: 103

How to modify url when language changes

I have a multilangual website in 2 languages english and fr when user changes the language to the en I want to change /fr/messages/111 to the /messages/111 for the english language.I use changeLang.php page to change the language passing the language(fr or en) I tried some ways but sometimes it causes redirect loops is there a method or an easy way to change the url acorrding to the language

Upvotes: 2

Views: 1432

Answers (1)

Wyzard
Wyzard

Reputation: 34563

Instead of having separate URLs for each language, consider having the same URL return either English or French text depending on the user's preference. Browsers send an HTTP header called Accept-Language that tells you the user's preferred language, and your application can use that to decide which text to send in its response.

This has the advantage that it works automatically, right from the beginning. The user doesn't have to do anything on your site to choose a language, because the user's browser should be configured to request the correct language by default (based on the OS locale).

Upvotes: 2

Related Questions