How to Redicrect web users by Browser Language

Nauman Zia Butt
1 min readOct 2, 2019

--

Let assume that you have a website containing 4 languages as German, French, Italian and English. If some one visits from germany or any user who use German language browser option, he/she will automatically redirected to known language web site version as www.yourweb.com/de

All you have to do is just copy the following code to .htaccess file and change the Root URL and sub directory.

.htaccess code:

Starting Code

— — — — — — — — — -

# Redirect visitors to the root domain path (e.g. www.yourwebsite.com) to the appropriate language version# Fallback to English version if no matching browser language defined# Based on language version being at e.g. www.yourwebsite.com/de/ # language starts with DERewriteCond %{HTTP:Accept-Language} ^de [NC]RewriteRule ^$ /de/[L,R=301] # language starts with FRRewriteCond %{HTTP:Accept-Language} ^fr [NC]RewriteRule ^$ /fr/ [L,R=301] # language starts with ITRewriteCond %{HTTP:Accept-Language} ^it [NC]RewriteRule ^$ /it/ [L,R=301] # else redirect to the English versionRewriteRule ^$ /en/ [L,R=301]

— — — — — — — — — -

Ending code

--

--