M
M
maiskiykot2018-07-21 14:01:05
PHP
maiskiykot, 2018-07-21 14:01:05

How to forward requests correctly?

There is a bilingual site. I changed the language through a redirect to the en/ pseudodirectory. This is how everything works, but there is a possibility that somehow the user will turn to the "wrong address", i.e. will enter the site.ru/en address while in the Russian session and vice versa. To do this, I made a forced redirect through PHP. Those.

if ($_SESSION['lang'] == en AND !preg_match("!\/en\/!",$_SERVER['REQUEST_URI'])
 redirect.

From Russian to English, such a trick works, but from English to Russian, a loop is obtained. In htaccess, the redirect rule is:
RewriteRule ^en/(.*)$ ./$1 [QSA,L]
I can't understand: why is it looping? What does he lack? Yes, even when changing the language it always throws off to the main page, i.e. either site.ru or site.ru/en/. Maybe something needs to be changed in htaccess, because looping does not depend on PHP code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2018-07-21
@Arik

it's better to keep the language code in the URL, and it's good for SEO. If someone switches from a search engine to the English version, will you give them Russian? It makes sense to store in sessions when you go to which additional pages in the form of personal accounts or settings, and everything that is publicly better with language prefixes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question