Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6837151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:26:31+00:00 2026-05-26T23:26:31+00:00

I have a little site that’s available in different languages which are selected based

  • 0

I have a little site that’s available in different languages which are selected based on the following criteria (increasing order of preference):

  1. Accept-Language sent by the browser
  2. A cookie specifying the preferred language
  3. The request path containing a language preference at the end

The site itself consists of only static HTML pages and insofar possible I’d like to keep it that way. I implemented the language selection via mod_negotiation, mod_rewrite and the following .htaccess file (shortened to omit declaration of languages and charsets):

Options FollowSymLinks MultiViews
DirectoryIndex index

Header set Pragma no-cache

RewriteEngine on
RewriteRule ^([a-zA-Z-]{2,5})$ index [CO=language:$1:.example.com:525600,E=LANG:$1]

SetEnvIf Cookie "language=([a-zA-Z-]+)" COOKIE_LANG=$1

SetEnvIf COOKIE_LANG (.+) prefer-language=$1
SetEnvIf REDIRECT_LANG (.+) prefer-language=$1

# plenty of AddLanguage and AddCharset calls

LanguagePriority en-us
DefaultLanguage en-us
ForceLanguagePriority Prefer Fallback

which has been working fine since August or so to allow for the following:

  1. No cookie present, Accept-Language takes over (thanks to MultiViews)
  2. Cookie present, the cookie’s language will be used (prefer-language)
  3. The request path is /es or similar and that will be used to (a) set a cookie and (b) set prefer-language to that value.

Now, I have a few more resources on the site which, thanks to MultiViews, can be selected via /resource instead of /resource.html and content negotiation and the cookie option still work fine for selecting the appropriate language here.

Now I wanted to expand URI processing so that things like /resource/en work in directly selecting the resource in a specific language, so that this doesn’t only work for /. I tried the following RewriteRule:

RewriteRule ^(([^/]+)/)?([a-zA-Z-]{2,5})$ /$2 [CO=language:$3:.example.com:525600,E=LANG:$3]

and it works insofar that the correct resource is sent and the correct cookie is set, but the preferred language apparently isn’t taken from the environment variable anymore. The only thing now forcing the language selection is the cookie, but that is still the same as before on that request, so I won’t see the new language until I refreshed the page. Nothing I tried so far with the rules had an effect on that behaviour. Interestingly, with this rule the old behaviour documented above still works fine. It’s only if I request something different from / that it does strange things.

This is on shared hosting (within a FreeBSD jail) so I can’t enable the rewrite log (as I don’t even know the physical path where the files are); besides, it quite clearly seems to ignore the environment variable and only using the cookie for setting the preferred language for some reason. And I haven’t figured out why so far. Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:26:32+00:00Added an answer on May 26, 2026 at 11:26 pm

    I solved the problem now by mixing the language selection between RewriteRule and SetEnvIf:

    SetEnvIf Cookie "language=([a-zA-Z-]+)" prefer-language=$1
    SetEnvIf REDIRECT_prefer-language "(.+)" prefer-language=$1
    SetEnvIf Request_URI "/([a-zA-Z-]{2,5})$" prefer-language=$1
    
    RewriteRule "^(([^/]+)/)?([a-zA-Z-]{2,5})$" /$2 [CO=language:$3:.example.com:525600]
    

    The rule now only sets the cookie and points to the correct resource, while the language selection is handled by matching on the request URI. Still feels weird, especially since it’s not easily visible when something needs to be prefixed with REDIRECT_, but at least it works now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a shopping site that works a little bit differently than the rest:
I have a site that need to get some data from a different sit
I have a Drupal site that needs to display a unique header image based
I have an ASP.NET 4.0 site that has links to another ASP.NET site (different
I have a little site, not yet online but that doesn't matter. Inside I
A little background, I have a client that has a legacy php site that
So, I've built a little site for a client that doesn't seem to have
I am working on a site that has a little flash gadget for which
I have a site that's been integrated with fb for a little while. Recently
I'm creating a little photo sharing site for our home's intranet, and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.