Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,110 of 9,110 pages
About the help in other languages
All help pages

Language switchers and addresses per language

Give each language its own address (path, host or host prefix), redirect the start page to the visitor's language, and build a language switcher with TranslationSA and the language_switcher operator.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/creators/website-creators/language-switcher-and-language-urls.md

On this page

Language switchers and addresses per language

This page is for website creators who give each language of a site its own address and a switcher between them. It covers the choice of addresses, the automatic redirect from the start page to the visitor's language, and the switcher template.

Contents

  1. Addresses per language
  2. Redirecting the start page to the visitor's language
  3. The language switcher
  4. Telling search engines
  5. Checklist

Addresses per language

ShapeExampleSet up with
Path per languageexample.com/de/MatchOrder=uri, URIMatchType=element, siteaccess named de (or a map)
Host per languageexample.de, de.example.comMatchOrder=host, HostMatchMapItems[]=example.de;site_de
Host and pathexample.com/de on one host, other hosts elsewherehost_uri with HostUriMatchMapItems[]
Setup, Languages: the languages content can be written in
Setup, Languages: the languages content can be written in

Paths are simplest (one certificate, one host); hosts suit country domains. The settings are in site.ini [SiteAccessSettings] (10.2).

Redirecting the start page to the visitor's language

With DefaultHostUriMatchMapItems[] an address without a language segment (example.com/) redirects once to the visitor's language, chosen by host and by the browser's Accept-Language, with one address per language and no cookie (Siteaccess by host prefix, and the redirect to the language):

# settings/override/site.ini.append.php
[SiteAccessSettings]
DefaultHostUriMatchMapItems[]=www.example.com;ger;site_de;strict;de
DefaultHostUriMatchMapItems[]=www.example.com;eng;site_en

The format is host;uri;siteaccess[;method[;language]]: a German browser goes to /ger, every other browser to /eng (the entry without a language). DefaultHostUriRedirect=disabled shows the page at the address itself instead of redirecting.

The language switcher

  1. Name the siteaccesses of the switcher, in each public siteaccess (or once in settings/override/):

    [RegionalSettings]
    TranslationSA[]
    TranslationSA[site_en]=English
    TranslationSA[site_de]=Deutsch

    Every siteaccess in it must also be in [SiteAccessSettings] RelatedSiteAccessList[]. LanguageSA[] maps a language to a siteaccess when the names do not follow the convention (settings/site.ini explains both).

  2. Print the switcher in the pagelayout with the kernel operator language_switcher (kernel/private/eztemplate/ezplanguageswitcheroperator.php). The ezwebin design's page_header_languages.tpl does it like this:

    {def $avail_translation = language_switcher( $site.uri.original_uri )}
    <ul class="languages">
    {foreach $avail_translation as $siteaccess => $lang}
      <li><a href={$lang.url|ezurl}{if $siteaccess|eq( $access_type.name )} aria-current="true"{/if}
             lang="{$siteaccess|wash}">{$lang.text|wash}</a></li>
    {/foreach}
    </ul>
    {undef $avail_translation}

    Each link goes through the module switchlanguage/to, which finds the same page in the other siteaccess (LanguageSwitcherClass=ezpLanguageSwitcher in site.ini). Give the lang attribute the language code your design uses (for example de) rather than the siteaccess name.

  3. Clear the INI and template caches.

Telling search engines

Search engines understand hreflang alternates between the language versions of a page. Exponential does not print them by itself; build them in the pagelayout from the same language_switcher result (<link rel="alternate" hreflang="de" href="...">), with full addresses (SEO basics for Exponential sites).

Checklist

  • To do: Each language has one address scheme, used everywhere.
  • To do: TranslationSA[] and RelatedSiteAccessList[] list every language siteaccess.
  • To do: The switcher links to the same page in the other language, not to the start page.
  • To do: The current language is marked for screen readers.
  • To do: Cached pages differ per language (they do: each siteaccess has its own cache).

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x