Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

home_redirect_lang

12 sites Security covered
View on drupal.org

Redirect visitors landing on the Homepage to their preferred language, based on previous browsing session.
Offering their native content as default.

This system uses Cookies (home_redirect_lang_preferred_langcode) to redirect visitors to the best matching Drupal defined language (if the cookie exists).

Internals

This module will perform the language redirect only on the Homepage and only once the user preferred language has been detected (aka when the visitor has chosen to change the language of any page).

Once the person has chosen to browse the website in any language, the language preference will be stored in a cookie (via JavaScript).

This cookie will then be used to trigger redirection when visiting the homepage on another language than the preferred stored language.

By using this behaviour (JavaScript storage and Cookie preferred language), we still allow visitors to change the homepage language and visit the website in any language.

Note there is no redirection trigger on any other page than the homepage.

As you may notice, the first visit can’t be handled - by design - with a non-existing cookie. In order to redirect a client upon its first visit, you can enable the module configuration Fallback redirection using visitor browser preferred language. This configuration will be used only when the Cookies (home_redirect_lang_preferred_langcode) does not exist.

Use custom Language Switcher

By default, this module will attach a custom JavaScript library to the Drupal core Language Switcher in order to create the home_redirect_lang_preferred_langcode cookie.

Still, you can create your own JavaScript and use the home_redirect_lang/common library to create the cookie.

  1. Add the home_redirect_lang/common on your own theme
    libraries:
      - home_redirect_lang/common
    
  2. Update your own JavaScript to use the cookie creation from the common library
    Drupal.homeRedirectLang.setPreferredLanguage('fr');
    
    // Prevent attempting to attach cookie if the common library is not available.
    if (typeof Drupal.homeRedirectLang == "undefined") {
      return;
    }
    
    let links = document.querySelectorAll('.language-link');
    
    links.forEach(link => {
      link.addEventListener('click', function (event) {
        var hreflang = event.target.getAttribute('hreflang');
        Drupal.homeRedirectLang.setPreferredLanguage(hreflang);
      });
    });
    

Getting Started

We highly recommend you to install the module using `composer`.

$ composer require drupal/home_redirect_language

Warning

In order for this module to works properly for anonymous user, you must disable the pache_cache module.

the Internal Page Cache assumes that all pages served to anonymous users will be identical, regardless of the implementation of cache contexts.

See https://www.drupal.org/docs/drupal-apis/cache-api/cache-contexts#internal

Supporting organizations

This project is sponsored by Antistatique.
We are a Swiss Web Agency, Visit us at www.antistatique.net or Contact us.

Credits

Thank you to all our wonderful contributors.
Homepage Redirection by Language is currently maintained by Kevin Wenger.

Activity

Total releases
4
First release
Mar 2025
Latest release
2 months ago
Release cadence
110 days
Stability
100% stable

Release Timeline

Releases

Version Type Release date
1.1.4 Stable Feb 13, 2026
1.1.3 Stable Aug 25, 2025
1.1.2 Stable Jun 3, 2025
1.1.1 Stable Mar 20, 2025