httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Victor Engmark <>
Subject [users@httpd] How to set prefer-language from a URL parameter without cookies?
Date Tue, 18 Aug 2009 09:07:16 GMT
Hi all,

I'm trying to do language auto-negotiation in .htaccess on version
2.0.63, and it mostly works (see code below). The only thing that
doesn't is the "env=prefer-language:%1" part, and I can't figure out
why. I tried asking at Stack Overflow
but although the answers are good, none of them seem to work. The
manual <>
didn't mention any gotchas and Google didn't help, so this is the last
try before going back to a PHP hack.

# Available languages
AddLanguage en .en
AddLanguage fr .fr
AddLanguage no .no

# Priority (highest first)
LanguagePriority no en fr

# Fallback to specified language priority if the browser doesn't
supply any of the supported languages
ForceLanguagePriority Fallback

# Language auto-negotiation
Options +MultiViews

# Set cookie when setting language in URL
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (?:^|&)language=(en|fr|no)
RewriteRule ^(.*)$ $1?

# Disable caching if the cookie was set
RewriteCond %{HTTP_COOKIE} language=(.*)
RewriteRule .* - [env=cookie_language:%1]
<IfDefine cookie_language>
	Header append Vary cookie
	Header set Cache-Control "store, no-cache, must-revalidate,
post-check=0, pre-check=0"

# Set preferred language from cookie if it exists
SetEnvIf Cookie "language=(.+)" prefer-language=$1

Victor Engmark

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message