Monday, November 8, 2021

Sitecore 8.1 - update configuration from multilingual to English only and handle en in the URL redirect rule

Recently, I got a request to fix an urgent issue, the alias was not working for a Sitecore instance 8.1,  I investigated this issue and found the language context got changed from en to the alias name.

How did we identify?

on the page source code, we keep the language code and while using the alias the language context got changed. I tried a lot to find the root cause that why Sitecore is changing the language to a wired language code from the alias and found that this was a known issue in Sitecore

Reference - https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0659458


so the issue was when a letter combination that matches any of the .NET Culture Codes is in that position, it gets resolved as a language (even if the language is not registered for Sitecore XP instance) and is not used to resolve anything else (for example, an alias or an item). If a resolved language is not identified, an error similar to the following appears:

I applied the first patch to Languages.AlwaysStripLanguage to false, it worked for me but the problem was there were a few existing URLs with EN, and those started giving 404 errors.

Now, I need to keep all those URLs live,  the easiest solution was the redirect rule.

I got some good references from this link https://community.sitecore.com/community?id=community_question&sys_id=5144e3691b0770d0b8954371b24bcb9d

and finally added the below configuration on the web. config and that way we have resolved the issue.


<rewrite>

  <rules>

<rule name="English Redirect" stopProcessing="true">

<match url="^en/(.*)$" />

<action type="Redirect" url="/{R:1}" />

</rule>

  </rules>

</rewrite>

  </system.webServer>


No comments:

Post a Comment