One of the many ways Sitecore will allow you to specify a language is in the url
example.com/en – English Language Site
example.com/fr – French Language Site
I came across a gotcha that had me stumped for a while.
To configure Sitecore to include the language code in the url, requires a change to the LinkManager in sitecore.config
<linkManager defaultProvider="sitecore"> <providers> <clear /> <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="asNeeded" languageLocation="filePath" lowercaseUrls="false" shortenUrls="true" useDisplayName="false" /> </providers> </linkManager>
What needs to be changed is languageEmbedding. This needs to be altered from asNeeded to always
As we don’t alter the web.config to make Sitecore upgrades easier, create a Sitecore patch file to make the modification
<linkManager> <providers> <add name="sitecore"> <patch:attribute name="languageEmbedding">always</patch:attribute> </add> </providers> </linkManager>
All done. the language code of the selected language is now included in the url.
When you download the latest version of Sitecore, (currently version 8) and follow the instructions to create a Visual Studio solution you are left with default.aspx in the root of the site.
Leaving this page in a Sitecore 8 MVC based solution, was preventing the language selector from working correctly on the home page of the site.
So attempting to go to example.com/en instead of loading up the configured site homepage, the default.aspx page is presented instead.
If you attempt to use the sc_lang parameter on the home page, ie example.com?sc_lang=en, the correct home page and the language is set correctly.
After much poking around Google, and not finding a solution, I was about to create a custom pipeline to attach a debugger to the site to determine what was going on, I decided to delete default.aspx file in the site root folder.
Deleting the default.aspx file solved the problem.
Who knew that this was the problem.