Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question