I use "Determine the language from the browser's language settings" after moving the domain from *dev* to live this doesn't seem to work at all. I'm aware of drupal's problem of getting the browser language when the page cache is enabled and implemented:

https://drupal.org/comment/reply/339958#comment-7573597

Which tries to serve the correct page on hook_boot. This isn't working as expected even when disabling redis with ?noredis=1 & the cache/NO.txt flag.

Comments

muschpusch’s picture

I think this could be a fix:

map $http_accept_language $lang {
        default en;
        ~*de de;
        ~*en en;
}

location ~ \.php$ {
                if ($args = '') {
                        rewrite ^/index.php$ /$lang redirect;
                }
                if ($args = 'q='){
                        rewrite ^/index.php$ /$lang? redirect;
                }
}

But which nginx file is save to use for one domain only and is not overwritten by aegir?

omega8cc’s picture

Component: Code » Documentation
Category: bug » support
Priority: Major » Normal
Status: Active » Closed (works as designed)

There is no workaround to this if you need to hit Drupal on every request. You must to (almost) disable Speed Booster (not Redis), as explained in the hint #4 at http://omega8.cc/how-to-disable-all-caching-and-aggregation-115

muschpusch’s picture

i dont think you need to hit drupal on every request but the language can be defined as in #1 on nginx level. I'm failing due to my limited nginx knowledge

i added nginx_vhost_include.conf in post.d


# not allowed here and it seems like $http_accept_language isn't available at all :/
#map $http_accept_language $lang {
#        default en;
#        ~*de de;
#        ~*en en;
#}

location ~ \.php$ {
        if ($host ~* ^(www\.)?(SOMESITE\.com)$) {
                if ($args = '') {
                        rewrite ^/index.php$ /$lang redirect;
                }
                if ($args = 'q='){
                        rewrite ^/index.php$ /$lang? redirect;
                }
        }
}
 

I don't wanna moan but your proposed fix is renaming the site to *.dev.* which besides being ugly also denies the site to all search engines (ugly could be fixed using an alias etc). At least without visitors you won't need the caching...

omega8cc’s picture

You do have to hit Drupal on every request if you need to dynamically redirect requests to the correct URL.

This can't be done with custom map, because you would need to modify main server config file, patch Provision etc.

The solution is not about dev URL, please make sure to really read the hint #4 at http://omega8.cc/how-to-disable-all-caching-and-aggregation-115

Of course you could add custom Nginx config to handle redirects (but not for index.php), but you would need to use proper variables, and since there are no nested IFs available, it is better to allow Drupal to manage them, and to make it possible, simply lower Speed Booster cache to 1s - this is what .dev. in the URL does automatically, and for non-dev URLs you must do the same in the local.settings.php

muschpusch’s picture

Ok thanks a lot! This works. It's a shame to disable your caching stuff but it makes sense...

For reference:

Hint: To force lower than default Speed Booster cache TTL you could add one extra line in the local.settings.php file: header('X-Accel-Expires: 1'); and if there are still issues to debug, you could disable Speed Booster completely with this line: header('X-Accel-Expires: 0'); – but please remember that disabling Speed Booster permanently is not allowed in our hosted environment.

gagarine’s picture

Version: » 6.x-2.0-rc8
Issue summary: View changes

This is the code I posted on http://drupal.stackexchange.com/a/121347/1761 . I copying here because this question show up on Google, hop it help.

/**
 * hook_boot
 */
function youmodule_boot() {
  // Check if it's the front page
  // using hook_boot we avoid wasting resources
  // It's to early to use drupal_is_front_page because and we should avoid loading unnecessary extra resource
  if ($_GET['q'] == '') {
    // http_negotiate_language() is a better option but require  pecl_http >= 0.1.0
    // Locale::acceptFromHttp() require intl extension
    $langBrowser = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);

    // Get the activated language
    $langAvailable = language_list();

    // set a default in case the language is not avaible
    $lang = 'en';

    if(isset($langAvailable[$langBrowser]) ){
      $lang = $langAvailable[$langBrowser]->prefix;
    }

    $http_response_code = 302;
    header('Location: ' . $lang, TRUE, $http_response_code);

  }
}