In EPiServerFramework.config it’s possible to configure default language for different hosts. Unfortunately they’re only used for incoming request and not outgoing external URLs. If we inspect the source for the language menu at www.episerver.com the links looks like this:

<ul id="languageDrop">
    <li><a href="http://www.episerver.com/About-Us/">English</a></li>
    <li><a href="http://www.episerver.se/sv/Om-oss/">Svenska</a></li>
    <li><a href="http://www.episerver.no/no/Om-oss/">Norsk</a></li>
    <li><a href="http://www.episerver.dk/dk/About-Us/">Dansk</a></li>
</ul>

The language segments are preserved although changing host would set the correct language. I’m not an SEO expert, but I’ll guess you don’t score extra points at search engines, when serving exactly the same page from several URLs. Of course using canonical tags will fix this, and perhaps the search engines don’t care. Nevertheless, the pedant in me doesn’t like it.

In my opinion it gets even worse when linking to a specific language version of a page from editorial content. In this scenario you would probably not have the same programmatic control over generated URLs as in the language menu.
<a href="http://localhost.com/no/artikkel">Link to Norwegian article</a> 

Last but not least. Have you ever worked with multilingual sites and subscriptions? 

The solution to managing hosts

The Epinova.SiteHostUrls plugin addresses all these scenarios. Once your languages and hosts are configured in EPiServerFramework.config you’re done. There is no need to deal with host switching from code. It just automatically works, even for subscriptions which runs without any http context. The previous examples now looks like this.

<ul id="languageDrop">
    <li><a href="http://www.episerver.com/About-Us/">English</a></li>
    <li><a href="http://www.episerver.se/Om-oss/">Svenska</a></li>
    <li><a href="http://www.episerver.no/Om-oss/">Norsk</a></li>
    <li><a href="http://www.episerver.dk/About-Us/">Dansk</a></li>
</ul>

<a href="http://localhost.no/artikkel">Link to Norwegian article</a>

The first version of the plugin was an URL rewriter, but I realized that it would lead to complications on sites with custom URL rewriters. The present version uses the Global.UrlRewriteProvider.ConvertedToExternal event. This enables the URL rewriter to take full control over the actual URL, and the plugin only changes host on the external urls.

In your siteHosts configuration It’s possible to configure a host to serve multiple languages (.com/es). Support for specified ports and wildcard ports are also supported.

<siteHostMapping>
  <siteHosts siteId="Epinova.Research">
    <add name="*" language="no" />
    <add name="localhost.no" language="no" />
    <add name="localhost.se" language="sv" />
    <add name="localhost.com" language="en" />
    <add name="localhost.com/es" language="es" />
   
   <add name="localhost.se:1199" language="sv" />
   <add name="localhost:*" language="no" />
  </siteHosts>
</siteHostMapping>

When using a dedicated publishing server I would recommend disabling the plugin on that server. This prevents host switching and keeps editors logged in on the current domain even when switching languages.

<section name="siteHostUrlPrepender" type="Epinova.SiteHostUrls.Configuration.ModuleSection, Epinova.SiteHostUrls" />
  </configSections>
  <siteHostUrlPrepender disable="true" />

Availability

The Epinova.SiteHostsUrls plugin is available for free from EPiServer’s NuGet feed.