Language specific URLs in Sitecore

I got a question the other day on how to render language specific URLs in Sitecore. Language specific meaning: and

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">
        <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" addAspxExtension="true" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="always" languageLocation="filePath" shortenUrls="true" useDisplayName="true"/>

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!


2 thoughts on “Language specific URLs in Sitecore

  1. There is one small catch that might cause problems: Display name don’t have any default validation (right?). Web-editors might use some exotic characters that will be used in the URL. From a SEO point of view this might not be optimal also I think it might break the URL completely.

    It guess it’s possible to implement the same kind of validation as the “ItemNameValidation” regular expression: [\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$

    • That is true, one would have to setup validation for the display name field or use some kind of rewriting in the linkManager.

Leave a Reply

Your email address will not be published. Required fields are marked *