Technology

blog

Avoid displaying pages without a language version

Posted 18 November 2011 6:31 PM by Marek Musielak

This post concerns Sitecore 6.5.0 (rev. 110818).

The Sitecore CMS allows you to create multiple versions of the pages for each of the languages supported by your site. Still, sometimes you may want to have particular pages translated into to a certain subset of the languages, e.g. if you have French content that should be available for end users in just France and Canada. The problem is that when you try to access the page in a language which does not have a supported version, you won't get a 404 error, but be displayed an empty page.

Now, to give you more context, assume that you want to run a competition targeted at just your UK customers. Our site has multiple languages as we have branches in many countries. We create a competition page for just the en language only. We publish the page, open it in a browser and we get:

However, when we try to access the page in a language that has no translation for the page, surprisingly there is no 404 page, instead we get:

Despite the fact that there is no version in Polish, pl language, we are still able to access the url. How do you avoid this? The solution, I recommend uses Sitecore processor functionality. I've created my own processor which is executed within httpRequestBegin just after the ItemResolver processor.