Language specific URLs in Sitecore

I got a question the other day on how to render language specific URLs in Sitecore. Language specific meaning: http://www.domain.com/company/about-us.aspx and http://www.domain.com/foretaget/om-oss.aspx

Resolving URL

When resolving a URL in Sitecore the httpRequestBegin-pipeline looks at the domain part of the URL to find the correct site defined in web.config. Somewhere along the line the context language is also resolved and added to the current request parameters. The directory part of the URL is parsed to find the matching item using the name of the items.

Note: There are of-course a lot of other processors in the
httpRequestBegin-pipeline but let's talk about them another time.

Matching correct item

Let’s say we have a rootPath and startItem defined in web.config with values “/sitecore/content/” and “/home”. Then when a directory of an incoming URL is “/company/about-us” the ItemResolver-processor will try to find an item under “/sitecore/content/home” named “company”, recursively it will look for an item under “company” named “about-us”.  If the processor can’t find an item with the corresponding name it starts looking for items with corresponding “Display name”-field value in the current request language (“Display name”-field is unversioned) and returns first item found.

Generating language specific links

In order to render the links using the “Display name”-field value there is a simple setting in the “linkManager” setting in web.config called “useDisplayName”, set this to “true” and links are generated in the display name for the corresponding language. If no display name exists item name is used instead.

<linkManager defaultProvider="sitecore">
      <providers>
        <clear/>
        <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" addAspxExtension="true" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="always" languageLocation="filePath" shortenUrls="true" useDisplayName="true"/>
      </providers>
    </linkManager>

It is really as simple as that…

Note: While implementing this you might also want to add language
embedding to all URLs, just set "languageEmbedding" to "always"
and you are all set.

That’s it, happy coding!

Share