homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Redirect by Accept-Language question

Msg#: 4074067 posted 2:39 am on Feb 4, 2010 (gmt 0)

I know that I can redirect visitors to a website by looking at their browser's preferred language setting, thus:

RewriteCond %{HTTP:Accept-Language} de [NC]

Now the question I have is, how do I know that the person having set up that browser does not only speak German, but actually prefers it? I.e. how do I know that someone who has set his browser to prefer English and French over all other language versions of a website prefers English over French?

Is there a fixed order to the language codes in the Accept-Language-header (or wherever it is sent)? What does this header look like?

I remember seeing things like "en=0.8,fr=0.2" or some such thing. Also I remember code like:

RewriteCond %{HTTP:Accept-Language} ^en [NC]

checking if "en" is the first language in the list.

How does this actually look like, and is there a resource (like the Apache docs) that explains this extensively?

Thank you for your help.

Ah, and P.S.: I do understand the problems with this method of redirection (the Frenchman in China using an internet cafe with browsers sending a preference of Chinese), so there is no need to lecture me on the fuzziness of this technique ;-)



WebmasterWorld Senior Member encyclo us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4074067 posted 2:59 am on Feb 4, 2010 (gmt 0)

Welcome to WebmasterWorld manfredkooistra :) I've never tried using mod_rewrite for this - I don't think you're using the right tools here. Apache has a dedicated module for content negotiation which handles language negotiation:

http://httpd.apache.org/docs/2.2/content-negotiation.html [httpd.apache.org]


Msg#: 4074067 posted 10:25 am on Feb 4, 2010 (gmt 0)

Hello encyclo,

thank you for the welcome :-) and thank you for that link.

The text on that page seems to imply that the language with the highest preference comes first. In the section headed "The Negotiation Methods" a series of tests is given, that Apache runs through, the second and third of which are:

"2 Select the variants with the highest language quality factor.
3 Select the variants with the best language match, using either the order of languages in the Accept-Language header (if present), or else the order of languages in the LanguagePriority directive (if present)."

The third rule seems to imply that the first language given is the preferred one, but the fact that the second rule is needed at all (and comes first), must mean that it is more than possible that something like "Accept-Language: fr; q=0.5, en; q=1.0", where the preferred language comes second, can be sent by a user agent and needs to be provided for.

So it seems that I cannot count on the language with the highest quality factor to come first.

I must admit that extracting the language with the highest quality factor in an htaccess is beyond me though it can easily be done in PHP, so I could do it. But maybe someone out there knows if maybe the languages are actually ALWAYS arranged in a descending order by preference, with the language with the highest quality factor coming first.


Msg#: 4074067 posted 10:31 am on Feb 4, 2010 (gmt 0)

I just googled a bit (should have done that first, before posting here *shame*) and found several pages stating that: "The order in which the values appear in the header determine the hierarchy of importance." (This is from an IBM website, so I lean towards believing it.)

So my question is answered.

Thank you! :-)


WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4074067 posted 4:26 pm on Feb 4, 2010 (gmt 0)

One statement that you may not have found in your search is that browser settings (language preferences) and geolocation based on the visitors' IP addresses are unreliable. Consider Switzerland (Deutch, French, Italian), Canada (English and French), Belgium etc. Consider also "internet cafes," where the user cannot control the browser language preferences.

Take a look at the major international sites, and you'll notice that many present a world map or a row of small national flags for the user to click on. From a usability standpoint, this is the best method, in my opinion -- Give the visitor a direct choice in real-time, and save the result in a session cookie (expires when browser is closed) or, as a user option, a 'permanent' cookie (expires at some future date). Otherwise, some users may be annoyed or inconvenienced by your attempts to correlate their machine settings and ISP location with their preferred (or only) language.

You may choose to present the initial page in a language based on a combination of the browser preferences and geolocation, but even if these settings are completely consistent with each other, it's still best to present the direct choice on your pages.

This is not primarily a technology problem, but a usability problem.



Msg#: 4074067 posted 5:39 pm on Feb 4, 2010 (gmt 0)

jd, thank you, I understand this. My situation is very special and I believe my solution is the best I can do under the circumstances.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved