• Htaccess redirect by user language

    Instead of writing custom snippets for php headers its faster to redirect website visitor to “his” language by using .htaccess rewriting rules (mod_rewrite should be enabled though and certain permissions allowed for you to change htaccess directives)

    so, lets imagine you already have language support on website by entering corresponding language as first argument in url:

    http://yourdomain/en/index/ for english speaking visitors
    http://yourdomain/fr/index/ for french speaking visitors
    

    in order to redirect these visitors by default when they enter a site, you may write tricky cookies or PHP snippets that grab User Agent Language, but for me somehow this approach turned out to be cool enough in order not to make site engine not to support feature that is needed in one of 30 pages.

    RewriteEngine on of course is already there since i already have user friendly url’s, so i add these lines to .htaccess

    RewriteCond %{HTTP:Accept-Language} ^fr [NC]
    RewriteRule ^$ fr/index/ [L,R=301]
    RewriteRule ^$ en/index/ [L,R=301]
    

    First line detects “Accept-Language” header in user agent and if it is “fr*” for any french speaking visitor, i redirect him to french site on second line.
    Third line is a fallback for default English language site.

    IF you dont have friendly url’s but want to start having some right now, then just add RewriteEngine on on .htaccess file in your site root.

    RewriteEngine on
    RewriteCond %{HTTP:Accept-Language} ^fr [NC]
    RewriteRule ^$ index.php/?language=fr [L,R=301]
    RewriteRule ^$ index.php/?language=en [L,R=301]
    

    Htaccess is a tricky thing, so you might need additional Options but that goes beyond this post. Cheers!

237 Comments


  1. Your page looks a bit strange when i use my mobile browser on my iphone. You want to check that please.

  2. Thanks for any some other fantastic post. The place else can anybody get that version of information in such the best way of writing? I’ve a presentation up coming week, and I am around the look for such advice. pobierz darmowy program do pit

  3. Sewing Machines… [...]any time to read or go towards the content or maybe internet web sites we surely have associated with[...]…

  4. yay google is my king aided me to find this great web site ! .

  5. This is among the good reasons why I keep returning to this blog site. This blog is a great deal of help and advice and I can’t wait to get started on making use of them. I like how it’s obvious that you made a ton of time and effort in searching. I detest it when I study postings that are 500 words long but are incomplete in message. It’s like they just want to catch you in and they are not really offering something compelling. So thank you!

  6. Hello. Cool write-up. There’s an concern with the web site in internet explorer, and you may want to test this… The browser is the marketplace chief and a large element of other folks will miss your excellent writing due to this issue.

  7. This design is spectacular! You certainly know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fantastic job. I really loved what you had to say, and more than that, how you presented it. Too cool!

  8. I’m not sure exactly why but this weblog is loading incredibly slow for me. Is anyone else having this problem or is it a problem on my end? I’ll check back later on and see if the problem still exists.

  9. Thank you for the sensible critique. Me & my cousin were just preparing to do some research on this. We grabbed a book from our area library but I feel I learned a lot more from this post. I am quite glad to see such great info being shared freely out there…

  10. donald trump says:

    Thanks, I have been looking for info about this topic matter for ages and yours is the greatest I have identified so far.

  11. whoah this weblog is fantastic i actually like reading your posts. Maintain up the great function! You already know, lots of persons are seeking round for this information, you can aid them greatly.

  12. Andrew Pelt says:

    I have been scanning this blog for awhile now and I just wanted to comment since this post is so awesome. Keep up the good work!

  13. Crazy Taxi says:

    Quite good post, thank you a good deal for sharing. Do you’ve got an RSS feed I can subscribe to?

  14. What a lovely blog page. I will certainly be back again. Please maintain writing!

  15. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz respond as I’m looking to design my own blog and would like to find out where u got this from. thanks

  16. I surely didn’t know that. Learnt 1 thing new these days! Thanks for that.

  17. here says:

    That’s what i call “great post”. Thank you so much.

  18. Excellent post. I learned a lot reading it. Thanks.

  19. Excellent post. I learned a lot reading it. Thanks.

  20. Excellent post, mate! Thanks for the useful information

  21. That’s what i call “great post”. Thank you so much.

  22. Excellent post, mate! Thanks for the useful information

  23. Gokkasten says:

    Some really select content on this website , saved to favorites .

  24. cio lists says:

    Excellent post. I learned a lot reading it. Thanks.

  25. Jenny Anderl says:

    Pretty! This was an extremely wonderful article. Thank you for supplying this info.

  26. Excellent post. I learned a lot reading it. Thanks.

  27. I’ve been absent for a whilst, but now I remember why I used to love this blog. Thanks , I’ll try and check back much more regularly. How regularly you update your site?

  28. This data is bit incomplete, I should say that the homework was done fantastic, possibly the biggest problem emerged in the event you experimented with build this data and also offer the item. Undoubtedly took action now your easiest and i get pleasure from the point that this will support too, you ought to study alternative posts in addition to create your personal posting undoubtedly concise plus undoubtedly comprehensible. I will Pm anyone lots of the strings concerning this theme so that the when folks go to forum along with post something genuinely educational comparable to this, it is going to be a lot more potent and beneficial to all.

  29. Excellent post. I learned a lot reading it. Thanks.

  30. That’s a great post. Thank you so much.

  31. Good put up! GA can additionally be my biggest earning. Nevertheless, it’s now not a much.:) http://www.mygolfnews.net

  32. webcam sex says:

    Im no professional, but I consider you just crafted an excellent point. You undoubtedly comprehend what youre speaking about, and I can really get behind that. Thanks for being so upfront and so truthful.

  33. That’s a great post. Thank you so much.

  34. The book is excellent, but this review is not exactly spot-on. Being a Superhero is much more about selecting foods that heal your body, not just eating meat/dairy-free. Processed foods like those mentioned in this review aren’t what Alicia is trying to promote. In case you aren’t open to sea vegetables (and yes, I’m talking sea weed), just stop at vegan.

  35. That’s a great post. Thank you so much.

  36. free vpn says:

    Thanks so much for this awesome info.

Trackbacks/Pingbacks

  1. Gabste9
  2. Dressage chiens
  3. Social Fan Exchange
  4. early childhood education
  5. Learn Piano
  6. cafelearn72

Leave a comment