<Sitecore> languageEmbedding=always, but language is removed manually from url still works

I had configured "languageEmbedding=always", it works well, however, when the language was removed manually from url bar of browser, it won't redirect or add the language back, here is an example:

http://app.local/de/index -> good

http://app.local/index -> still available, but not match requirement, we hope it should refresh and change url to http://app.local/de/index or current language.

The url MUST ALWAYS with language.

Here is my current link manager configuration

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

How to do it?

The language embedding and your link provider is to create the links, not to resolve them.

If you want te verify the language in the url and redirect when it is not there, you could add a processor to the httprequestbegin pipeline and put your logic in there. http://insitecore.tumblr.com/post/37734162227/sitecore-httprequestbegin-pipeline-in-detail

Like Gatogordo said, the languageEmbedding setting is used by the LinkManager when rendering item urls. The site will always resolve to the default language without the language code in the url. We ended up doing the redirects in the load balancer because we already had some redirect login in there to begin with.

I Solved this requirement by the following hard code

    var mustHave = "/" + Sitecore.Context.Language;
    var isWithLanguage = HttpContext.Current.Request.Url.AbsoluteUri.Contains(mustHave);
    if (!isWithLanguage)
        var urltmp = Helper.GetUrl(Sitecore.Context.Item.ID.ToString(), Sitecore.Context.Language.ToString());


This condition code I put in the layout page, so it will be validated each time page load.

  • Why do you actually want a redirect? Is a canonical on your page not sufficient?
  • @Gatogordo The requirement is from my co-worker, he is in charge of SEO optimists, the website is with canonical, I have no idea what is the benefit of this requirement....
  • Is it easier to solve this issue by configuring IIS?
  • Don't think so.. if you get a url without language, IIS won't know to which language it should redirect.
  • If someone enters a URL without a country code the URL should rewrite to the correct version.
  • In that case you should add a processor as in the answer.
  • so you had done that always keep language in URL by setting load balancing? I have never configured it, is it complicate by doing like that? Maybe I can ask our IT dept.