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
- Addresses per language
- Redirecting the start page to the visitor's language
- The language switcher
- Telling search engines
- Checklist
Addresses per language
| Shape | Example | Set up with |
|---|---|---|
| Path per language | example.com/de/ | MatchOrder=uri, URIMatchType=element, siteaccess named de (or a map) |
| Host per language | example.de, de.example.com | MatchOrder=host, HostMatchMapItems[]=example.de;site_de |
| Host and path | example.com/de on one host, other hosts elsewhere | host_uri with HostUriMatchMapItems[] |

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_enThe 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
Name the siteaccesses of the switcher, in each public siteaccess (or once in
settings/override/):[RegionalSettings] TranslationSA[] TranslationSA[site_en]=English TranslationSA[site_de]=DeutschEvery 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.iniexplains both).Print the switcher in the pagelayout with the kernel operator
language_switcher(kernel/private/eztemplate/ezplanguageswitcheroperator.php). The ezwebin design'spage_header_languages.tpldoes 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=ezpLanguageSwitcherinsite.ini). Give thelangattribute the language code your design uses (for examplede) rather than the siteaccess name.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[]andRelatedSiteAccessList[]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).
Related pages
- Building a multilingual site
- Right-to-left sites
- Translations and languages
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
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.