3

After configuring the sitecore Habitat based on the instruction from GIThub, we could see sometimes locale code is getting added and not added to the URL.

This is happening inconsistently.But the content are loading as expected.

Both below URL are working fine

http://habitat.dev.local/en/About-Habitat/Getting-Started

http://habitat.dev.local/About-Habitat/Getting-Started

The same is happening EN and DA locale. Is there a way to show the locale code permanently in the URL

2
  • Find LinkProvider in sitecore.config file. There is languageEmbedding. Set it to true;
    – Marek Musielak
    Commented May 26, 2017 at 11:40
  • Yes. This works
    – PVM
    Commented May 26, 2017 at 17:13

1 Answer 1

6

This is controlled by the languageEmbedding attribute on your linkManager.

By default, Sitecore adds the language code to your URLs asNeeded. Which is a bit fuzzy; but essentially Sitecore should add it when it isn't sure of your current Context.Language and wants to make sure the URL points to the desired result.

Other options are:

  • Always (always enforce language in the url, this is what you ask for)
  • Never

You can find the configuration in your Sitecore.Config located under App_Include.

  <!-- Options (first is default):
           addAspxExtension: false | true (If you set this to false, remember to configure IIS to map all requests (*) to ASP.NET)
           alwaysIncludeServerUrl: false | true
           encodeNames: true | false
           languageEmbedding: asNeeded | always | never
           languageLocation: filePath | queryString
           lowercaseUrls: true | false
           shortenUrls: true | false
           useDisplayName: false | true
    -->
  <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>

It is not recommended practice to modify this file directly however. I recommend you implement any changes as a Sitecore Config Patch file. Described many places, for instance in Create a Sitecore LinkProvider to use different LinkManager.

1
  • yes. this works
    – PVM
    Commented May 26, 2017 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.