Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module redirects visitors to their preferred language on the homepage, using cookies to remember their choice. It can also offer a fallback redirection based on browser settings for first-time visitors.

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
5 months ago
Releases (12 mo)
2
Maintenance
Active

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