Hide The Language Embedding for a Specific Language in Sitecore SXA Multilingual Site

Share:
Sitecore SXA 10.1 – Hide The Language Embedding for a Specific Language in Sitecore Multilingual SXA Site.
This is very common recommendation not only from SEO point of view but also client's requirement to not embed default language in multilingual site. 
In our case client want to not embed english (en) language in URL.

https://www.yourdmain.com/test-page
https://www.yourdmain.com/hi-IN/test-page


When you create a page in sitecore, one for english (en) and another for hindi (hi-IN), the default url will be as following:
https://www.yourdmain.com/en/test-page
https://www.yourdmain.com/hi-IN/test-page

But unfortunately to meet the SEO/client's recommendation in Sitecore OOTB there is no option available where we can simply switch on or switch off to achieve it.
But Sitecore provide a way, With SXA, you can select a different link provider for different sites. This can be useful when you have multiple sites that all have different link requirements.
You can read here in official Sitecore URL https://doc.sitecore.com/en/developers/sxa/17/sitecore-experience-accelerator/add-and-select-a-custom-link-provider.html


Let's follow the below STEPS to achieve the above requirement. We have separated the steps in two groups. One for Language embedding and another for remove language cookie.


STEPS for language Embedding:
  1. Create a custom LinkProvider.
  2. Add a patch for new LinkProvider
  3. Add the LinkProvider to Sitecore
  4. Set the properties in Sitecore
STEPS for language cookie removal:
  1. Create a processor to remove the language cookie.
  2. Add a patch for new processor
  3. Add the processor to Sitecore

STEPS TO REMOVE THE LANGUAGE EMBEDDING FROM URL.

1. Create a custom LinkProvider
First of all we create the custom LinkProvider. Please note that this example is based on the LocalizableLinkProvider that is introduced within SXA, but you can extend any LinkProvider.

SkippableLanguageEmbeddingLinkProvider.cs


NOTE: GetItemUrl(Item item, UrlOptions options) is obsolete since SXA 9.3. It will be removed after two consecutive releases so we are using GetItemUrl(Item, ItemUrlBuilderOptions) instead.

2. Adding a patch for new LinkProvider
To add the new LinkProvider to Sitecore, all you need to do is to register it through a config file.



3. Add the LinkProvider to Sitecore
We have to define the skipLanguageEmbeddingInURLForLanguages setting on our site. When using SXA you can do this on your Site Grouping.



4.  Set the properties in Sitecore

Open your Site Grouping, scroll to Other Properties and add the skipEmbedLanguaInURLForLanguages property

In the Content Editor, navigate to sitecore/content/<tenant>/<site>/settings/Site Grouping/<site> and in the Basic section, in the Link Provider name field, enter the name of your custom provider.






STEPS TO REMOVE THE LANGUAGE COOKIE.

1. Create a processor to remove the language cookie.
To make sure Sitecore does not take the language from the cookie, when nothing is specified in the URL, we will have to remove the language cookie from the response. This way, the cookie will never be sent to the user.


RemoveLanguageCookieProcessor.cs


2. Add a patch for new processor
To make sure Sitecore does not take the language from the cookie, when nothing is specified in the URL, we will have to remove the language cookie from the response.



3. Add the processor to Sitecore
As explained in Step 3, open your Site Grouping, and add the following setting:





Now open your page or hover the Link, you can see the language is not embedding for en language.

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments