Sitecore Multi language site with the language code in the URL Gotcha

One of the many ways Sitecore will allow you to specify a language is in the url

eg

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 the web.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.

Gotcha

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.

Advertisements

My musing about anything and everything

Tagged with: , ,
Posted in Sitecore

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

%d bloggers like this: