Forum Moderators: phranque

Message Too Old, No Replies

Browser Language redirect?

         

Brian Harris

10:33 pm on Feb 7, 2007 (gmt 0)

10+ Year Member



I have no idea if this is possible at the apache level, i know its possible in php. This is what I'm looking to do.

I have two sites(both hosted on same server using virtual directories):
www.example.com (English Site)
www.example.de (German)

I'm developing www.example.de right now. When a user directly types in www.example.com and if their browser language is set to german, i want them to be redirected to www.example.de.

If the user is coming to example.com through a referal AND their browser is german than no redirect.

is this possible?

phranque

10:58 pm on Feb 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the Accept-Language HTTP Request header is the one that sends the browser setting(s).
you probably want to read up on content negotiation [httpd.apache.org].

jdMorgan

12:32 am on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Best practice is to always let the user choose his/her preferred language, rather than forcing it. Also, you cannot rely on HTTP_REFERER header being present in the request -- it is often not present.

Users prefer the solution of selecting by TLD (.com or .de) first, and using an on-screen option (like clicking on country name, language, or even national flags) second. You can save this preference as a cookie and then test it using mod_rewrite in .htaccess or from PHP or any server-side script as %{HTTP_COOKIE}. You have no guarantee that the browser language preference has been set by the user, so don't count on it -- Think internet cafes, Germans visiting London, and Englishmen working in Berlin.

Jim