H
H
hdtor2016-02-13 20:25:40
PHP
hdtor, 2016-02-13 20:25:40

Website in two languages?

Hello.
There is a site in two languages, languages ​​are selected and recorded in cookies, here is the code:

if($lang == "ru") {
  setcookie($_COOKIE['lang'], $lang);
} else { 
  setcookie($_COOKIE['lang'], "ua");
}

header("Location: " . $_SERVER['HTTP_REFERER']);

Everything works all good. But it took the site to open at the following link:
mysite.com/ru
mysite.com/en I
registered the following in .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{HTTP:Accept-Language} (ru) [NC]
RewriteRule .* http://mysite.com/ru [R=302,L]
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule .* http://mysite.com/ua [R=302,L]

But the problem is that the site is at the root. And it opens the ru or en folder. How to make both the first and second links open the root of the site?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Litvinenko, 2016-02-13
@edli007

There is a lang attribute in HTML

T
ThunderCat, 2016-02-13
@ThunderCat

So, calmly, there are other things like that too)
So, well, let's start with the fact that everything that comes to any URL that does not exist and to any URL that is not a picture/css/zhs/whatever else is thrown to index.php.
like this:
In .htaccess:

RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteRule !\.(js|ico|gif|jpg|png|css|pdf|mov|mp3)$ index.php

Next, parse the URL in the code, separating it by "/", if one of the languages ​​​​is in the right place, we change the display language to the desired one. Further, any magic of your choice - includes the desired language, a request to the database of language variables, an array of translation words - the options for perversions are not endless, but very diverse, in the 90s-00s people didn’t sculpt anything))
PS: READ ABOUT OBJECTS, MVC, MODERN DEVELOPMENT METHODS, FRAMEWORKS...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question