How to set prefer-language from a URL parameter without cookies?
am 18.08.2009 11:07:16 von Victor EngmarkHi 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?
[cookie=language:%1:.aspaass.no:7200:/,env=prefer-language:% 1,redirect=permanent]
# Disable caching if the cookie was set
RewriteCond %{HTTP_COOKIE} language=(.*)
RewriteRule .* - [env=cookie_language:%1]
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
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org