What is the correct method of directing the navigation of a website to a specific page based on the language of the user's browser?
I have a website (www.site.com) with the default language in English and I need it, when it is accessed in a browser with the Portuguese language (pt-br), it redirects the navigation to the subdomain that I created and already I hosted the translated files (br.site.com).
The same for Spanish (es.site.com) and Italian (it.site.com).
What should I do? What kind of code should I enter?
PS: I already have the pages translated and hosted in their subdomains . I just need to know how to identify the browser language and auto-route.
How is this done in the code? Javascript? PHP? Ajax? Via htacess? Does anyone have this line of code to share?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My site</title>
</head>
<body>
<p>The book is on the table.</p>
</body>
</html>