S
S
Sergey2014-06-21 19:43:00
htaccess
Sergey, 2014-06-21 19:43:00

Website language version, how to redirect by ip once?

There is .htaccess:

#RewriteEngine on

# редирект на русскоязычную версию сайта для русских, украинских, белорусских и казахских браузеров

RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{HTTP:Accept-Language} (ru|uk|by|kz) [NC]
RewriteRule .* http://site.ru [R=302,L]

# редирект на англоязычную версию сайта для всех остальных языков

RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule .* http://site.com [R=302,L]

It works and redirects as it should. Those. if people come from English-speaking countries, they will see the English version of the site. And that's great. But it may be that Russian-speaking people will come in while on vacation, for example. They will be transferred to English. version, they will choose the language and switch to Russian, but they will be thrown again. How to make it so that the redirect was only the first time?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vit, 2014-06-21
@butteff

You can set a cookie with a language when the user selects it manually. And in the presence of this cookie, do not redirect. Reading cookies in RewriteEngine is available, for example see here stackoverflow.com/questions/3978726/how-to-do-htac...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question