Personal Developer Site

Language dependent routing with .htaccess

2014-10-13 09:47:00
Read this in: Hungarian

As an owner of a multilingual Drupal 7 site, I have got some issues with language dependent routing. Although I've set the proper language detection inside Drupal every Hungarian users routed to the English front page which were empty (until this first English post). So this bug was a pretty annoying and a big (self) marketing killer to me because of empty English front page.
(FYI: In this semester I'm really busy with my courses on the university so I haven't got enough time to wrote not only Hungarian but also English posts. It's very sad to me...)

So when all my efforts failed with Drupal to set the proper language dependent routing for my Hungarian users to my Hungarian front page I've started to try other "hardcore" solutions to this problem. My first idea was using the .htaccess  file to solve this problem, Luckily this idea was really great. I've found a working solution very fast and after I've made a few tweaks on this solution, here is my working .htaccess code part:

  # On the frontpage if the browser language is hungarian then redirect to /hu
  RewriteCond %{HTTP:Accept-Language} (hu) [NC]
  RewriteCond %{REQUEST_URI} ^/$ [NC]
  RewriteCond %{QUERY_STRING} !(^q\=) [NC]
  RewriteRule ^(.*)$ /hu [L,R=302]

Recent Comments

Tweets by Me