Building sites on Sitecore which have different languages is easy. For example, you can implement the “XYZ” site in both English and Spanish versions using the default Sitecore site configuration.
In this post, I will explain how to setup a site which
- Has 2 language versions (eg: en-US and es-US).
- Use of a single domain for both sites (http://example.com).
- 2 different Sitecore item nodes in the content tree (Site ENUS & Site ESUS)
- Has language in the URL (http://example.com/en-us & http://example.com/es-us).
The content tree structure is as shown in the screenshot below:
To setup the above scenario, the use of VirtualFolder is required. Most examples I have seen for VirtualFolder does not make use of the language as value. Example:
By default, if we use the virtualFolder=”/en-gb”, when Sitecore loads the URL, it will take the “en-us” as the language and will load the item version “en-US” instead of loading the 2nd site. So, let see the different steps to achieve the above requirements.
In your SiteDefintion.config, you need to set the virtualFolder and physicalFolder value as the same. No need to create the physical location for the physicalFolder attribute value. Example of the SiteDefinition:
You need to set the LanguageEmbedded attribute to false since we will not need the Sitecore LinkProvider to carry the language within the path.
This is the most important part for the language to work as VirtualFolder. You need to set the value of the AlwaysStripLanguage setting to false.
You may patch the setting or change it from the Sitecore.config file. All you need to do is to search for AlwaysStripLanguage and change
<setting name=”Languages.AlwaysStripLanguage” value=”true”/>
<setting name=”Languages.AlwaysStripLanguage” value=”false”/>