Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Homepage Redirection by Language

Security covered Maintenance fixes only 14 sites

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.

Drupal 10–11

Ask your assistant about Homepage Redirection by Language

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
7
Tracked since
May 2024
Latest release
1 month ago
Releases (12 mo)
2 ▼ from 3
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
1.1.5 Stable 10–11 Aug 25, 2026
1.1.4 Stable 10–11 Feb 13, 2026
1.1.3 Stable 10–11 Aug 25, 2025
1.1.2 Stable 10–11 Jun 3, 2025
1.1.1 Stable 9–11 Mar 20, 2025
1.1.x-dev Dev 10–11 May 31, 2024
1.1.0 Stable 9–11 May 31, 2024