7

I've a site in x languages and each language has its own domain and language like

www.mycompany.de, www.mycompany.co.uk, www.mycompany.at, ....

Currently, I can force another language - e.g. German on the English site - on any of the sites like this: wwww.mycompany.co.uk?sc_lang=de-DE.

I want to prevent this.

Also, Sitecore's URL resolver will recognize other Display Names for an item. So for instance I can go www.mycompany.de/about-us on the German site, where only www.mycompany.de/ueber-uns should be allowed.

Is there one setting I just need to activate and this works out of the box? If not, what is the solution here?

  • This has nothing to do with Language Fallback functionality. Unfortunately, I'd say. But OOTB this is default behaviour of Sitecore. Am going to edit your question so as it doesn't mislead the casual reader to thinking the answer to your problem here is Language Fallback related. And we do need a good answer for this common problem on this site. – Mark Cassidy Mar 24 '19 at 1:39
  • Thanks Mark, that edit makes much more sense. – Pete Navarra Mar 24 '19 at 2:19
  • @MarkCassidy yes that sounds like the problem I have :-) – squadwuschel Mar 24 '19 at 9:10
4

I don't know of an ootb solution, this is how I usually "fix" this issue:

  1. Add a setting to the site definition that lists all available languages
  2. Add a a processor to the httpRequestBegin pipeline after the language resolver:

    <httpRequestBegin> <processor patch:after="*[@type='Sitecore.Pipelines.HttpRequest.LanguageResolver, Sitecore.Kernel']" type="xxx.LanguageResolver, xxx" /> </httpRequestBegin>

  3. In the processor:

    • Detect if the request should be handled (no Sitecore requests, only in normal mode, ...) and get out asap if not (performance)
    • Check if the language is available in the current site (based upon the setting created in 1) and redirect if it's not ok

You can find code for this on https://github.com/Gatogordo/EasyLingo

This will fix the first issue. For Sitecore recognizing urls you don't actually want, I usually don't block that but I do tell crawlers and such that I don't want those. You should do (at least) two things:

  • Always set a canonical url with the exact link you want for that page in that language
  • Add language headers to all pages, like <link rel="alternate" href="https://www.mycompany.de/ueber-uns" hreflang="de" /> and <link rel="alternate" href="https://www.mycompany.co.uk/about-us" hreflang="en" /> (do this for all languages in which the current page is available).

When using item language fallback, you can tweak the logic of the language headers and canonicals to your needs (hide pages that are a full fallback and set their canonicals to the original language).

If you really want/need to block those (faulty) requests you will need the current language and the current item to verify whether the request is ok or not. To do that you could add another processor to the httpRequestBegin pipeline but this time after the ItemResolver, as you will need the current item. You could request the the url for the current item from the LinkManager and compare that to the raw url. Test this thoroughly as a small error might cause infinite redirects ;)

  • solution one sounds good. I've also added the rel alternate links, but I need to be shure that no one can call the other url in my current portal and language. Isn't it possible to check this too in the Language Resolver? – squadwuschel Mar 25 '19 at 6:48
  • If you would like to block that, I would put a processor in the same pipeline but after the item resolver - you will need current language and item to define if the request is valid so waiting until after the item resolver might help. – Gatogordo Mar 25 '19 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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