N
N
Ninazu2018-10-27 20:33:11
htaccess
Ninazu, 2018-10-27 20:33:11

How to implement localization via URL?

The site has three localizations. ru , de and en . English is basic. The user visits the main page of the site for the first time at the address http://mysite.com/, sending a request Accept-Language: fr;q=0.9. Since French is not implemented, it redirects to the English version http://mysite.com/en/. The site has a search form that sends a POST request to a URL /search. There is no state saving on the server (sessions and analogues)
I tried to implement it through .htaccess, but I don’t know how to correctly implement URL generation for forms and how to pass the locale. And also how to substitute the locale in the URL if the user clicks on a link without a localehttp://mysite.com/faq

RewriteEngine On

#Локаль по умолчанию
RewriteCond %{HTTP:Accept-Language} !^(ru|de) [NC]
RewriteRule ^$ /en/ [L,R=302]

RewriteCond %{HTTP:Accept-Language} ^ru [NC]
RewriteRule ^$ /ru/ [L,R=302]

RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^$ /de/ [L,R=302]

#Перенаправлять все запросы на единую точку входа
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arris, 2018-10-28
@Arris

Cookies. If they are disabled, warn the user that in this case he will receive the site in the main language. Which one do you have? English?
If the user does not want to meet halfway - give him the default content.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question