How to set prefer-language from a URL parameter without cookies?

How to set prefer-language from a URL parameter without cookies?

am 18.08.2009 11:07:16 von Victor Engmark

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?
[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 for more info.
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

Re: How to set prefer-language from a URL parameter

am 20.08.2009 11:54:25 von Apache Admin

--0003255769469b8e2804718fbc64
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi,

I Show you an example of access manual from browser ..... having different
language support


AliasMatch ^/manual(?:/(?:de|en|es|fr|ja|ko|pt-br|ru))?(/.*)?$
"/usr/local/apache2/manual$1"


Options Indexes
AllowOverride None
Order allow,deny
Allow from all


SetHandler type-map


SetEnvIf Request_URI ^/manual/(de|en|es|fr|ja|ko|pt-br|ru)/
prefer-language=$1
RedirectMatch 301 ^/manual(?:/(de|en|es|fr|ja|ko|pt-br|ru)){2,}(/.*)?$
/manual/$1$2

LanguagePriority en de es fr ja ko pt-br ru
ForceLanguagePriority Prefer Fallback


It gives u an idea....

Amit
http://new-innovation.blogspot.com/








On Tue, Aug 18, 2009 at 2:37 PM, Victor Engmark wrote:

> 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
> <
> http://stackoverflow.com/questions/1280220/how-to-use-setenv -with-a-url-parameter
> >,
> 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 for more info.
> 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
>
>

--0003255769469b8e2804718fbc64
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,

I Show you an example of access manual from browser ..... havin=
g different language support


AliasMatch ^/manual(?:/(?:de|en|es|=
fr|ja|ko|pt-br|ru))?(/.*)?$ "/usr/local/apache2/manual$1"


<Directory "/usr/local/apache2/manual">
  =A0 Option=
s Indexes
  =A0 AllowOverride None
  =A0 Order allow,deny
=
  =A0 Allow from all

  =A0 <Files *.html>
  =A0=
     SetHandler type-map
  =A0 </Files>


  =A0 SetEnvIf Request_URI ^/manual/(de|en|es|fr|ja|ko|pt-br|ru)/ p=
refer-language=3D$1
  =A0 RedirectMatch 301 ^/manual(?:/(de|en|es|fr=
|ja|ko|pt-br|ru)){2,}(/.*)?$ /manual/$1$2

  =A0 LanguagePriority=
en de es fr ja ko pt-br ru

  =A0 ForceLanguagePriority Prefer Fallback
</Directory>
r>It gives u an idea....

Amit
logspot.com/">http://new-innovation.blogspot.com/



=A0 >




On Tue, Aug 18, 2009 at 2:37 PM, Victor =
Engmark <v=
ictor.engmark@gmail.com
>
wrote:
_quote" style=3D"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt=
0pt 0.8ex; padding-left: 1ex;">
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=3Dprefer-language:%1" part, and I can'=
;t figure out

why. I tried asking at Stack Overflow

< -with-a-url-parameter" target=3D"_blank">http://stackoverflow.com/questions=
/1280220/how-to-use-setenv-with-a-url-parameter
>,

but although the answers are good, none of them seem to work. The

manual < #rewriterule" target=3D"_blank">http://httpd.apache.org/docs/2.0/mod/mod_r e=
write.html#rewriterule
>

didn't mention any gotchas and Google didn't help, so this is the l=
ast

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=3D(en|fr|no)

RewriteRule ^(.*)$ $1?

[cookie=3Dlanguage:%1:.aspaass.no:7200:/,env=3Dprefer-langua ge:%1,redirect=
=3Dpermanent]



# Disable caching if the cookie was set

RewriteCond %{HTTP_COOKIE} language=3D(.*)

RewriteRule .* - [env=3Dcookie_language:%1]

<IfDefine cookie_language>

=A0 =A0 =A0 =A0Header append Vary cookie

=A0 =A0 =A0 =A0Header set Cache-Control "store, no-cache, must-revali=
date,

post-check=3D0, pre-check=3D0"

</IfDefine>



# Set preferred language from cookie if it exists

SetEnvIf Cookie "language=3D(.+)" prefer-language=3D$1



--

Victor Engmark



------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g">users-unsubscribe@httpd.apache.org

=A0 " =A0 from the digest: @httpd.apache.org">users-digest-unsubscribe@httpd.apache.org

For additional commands, e-mail: org">users-help@httpd.apache.org






--0003255769469b8e2804718fbc64--