How to redirect to same page for changing language via .htaccess config?

For example



  • Can you provide a bit more detail? Your question is not clear as written. eg, Are you expecting a request of the form /some-page/en/<some-url> and want to redirect to /some-page/de/<some-url> - although taken out of context, that type of language redirect doesn't really make sense unless there are some other criteria?
    – MrWhite
    Commented Jul 6, 2020 at 17:25
  • if url has param language from /some-page/{language}/<some-url> redirect to /some-page/{language}/<some-url>
    – Karen
    Commented Jul 6, 2020 at 18:08
  • But isn't that the same URL? Don't you mean redirect to {some-other-language}? So, is this just a simple redirect from A to B? It's not a "language redirect" as based on the user's preferred language or geo-targeting?
    – MrWhite
    Commented Jul 6, 2020 at 18:19

2 Answers 2


Automatic redirects for language are not user friendly and should not be used.

There are two common ways that language redirects are implemented. The first is by identifying the country a person is from based on IP address, and redirecting to the language of that country. There are several problems with this approach:

  1. Geo-IP databases are inaccurate and cannot pinpoint the country of a person 5 to 10% of the time.
  2. Some regions speak multiple languages (like French and English in parts of Canada), it is not always possible to choose a preferred language based on geographic IP address.
  3. People travel but still need access to your site in their native language even when in a foreign country.

The second method relies on the Accept-Language header that most browsers send. There are also problems with it. Most users don't know how or bother to configure their browsers to send appropriate information. Browsers default to sending an Accept-Language header that matches the language of the browser UI.

  1. Many browsers come in English and users know enough English for that to be OK, but would prefer your site in another language.
  2. Users that speak multiple languages may not have configured their browser with those languages and get redirected away from a language they speak.

In general, this is not a problem you need to solve. Most users don't ever get to content that isn't in their language. Search engines users almost always search for terms in their language and search engines send them to pages in their language. You can create a home page that has language choices for users that want to start there.

The better way to handle this situation is to provide a prominent notice and link at the top of the page when your server sees that the language of the page doesn't match the language in the Accept-Language header sent by the user. That notice might look something like:

This page is in French, but you prefer English according to your browser settings. Click here to view this page in English.

Such a notice can be prominent enough to let users get to their native language, but can also be ignored. If you automatically redirect for users, it is much harder for them to get back to their preferred language if the redirect was done in error.

  • 1
    "based on IP address" / "the Accept-Language header" - and neither of these methods can be reliably performed in .htaccess alone anyway.
    – MrWhite
    Commented Jul 6, 2020 at 18:22

You may use IP Geolocation technology.

It can help you detect your visitors locations, like country, state, city based on their IPs, and help you route your visitors to correct URLs, automatically showing different local languages. You may look into IP geolocation. Some provide tools requiring no code at all. It has pretty good data accuracy at country level; it's usually higher than 90%.

Besides, you can also provide a language selector on your webpage. It gives your users flexbility to switch between languages. A cookie could to used to identify individual users and save their language preference for future auto direction. In this way, IP geolocation technology can provide excellent user experience and engage with users effectively.

  • 1
    90% accuracy is not good enough for automatic routing via redirects taking visitors away from the language they are currently trying to view based on the URL. Switching 10% of your users to a language they don't understand is no way to run a website. You can use geolocation to redirect away from a base URL to a languge subdomain or you can use geolocation to suggest a language via a prominent notice on the page, however you shouldn't change the language based on that alone. Commented Aug 6, 2020 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.