Embed a language in a Sitecore URL

we created a multilingual website in FR, ES, EN from the old classic asp website (which was also in 3 languages). In the Old site, by default in English "en" was not embedded in the URL. but on our new sitecore site I have the language Embedding = "Always".

So, when we redirect from the old website to the new website for 301 redirects to Google, if I open my new website in French and redirect from the old website in English (this means that the URL doesn’t language, that is, "en") will point to the French version).

So how can I add "en" to url.

  HttpContext.Current.Request.RawUrl

I can use the above to get the source url, but I don't get how to display "en" in the browser url.

old links to sites:

www.abc.com/xyz.asp,
www.abc.com/fr/xyz.asp,
www.abc.com/es/xyz.asp

links to the new site:

www.abc.com/en/xyz.aspx,
www.abc.com/fr/xyz.aspx,
www.abc.com/es/xyz.aspx

thanks

+4
source share
5 answers

How did you handle the language on the old website? How did you find out that the user requested a page in EN / FR / ES?

Since you are redirecting 301 from your old site, you need to process the language attachment in the URL from your old site. Processing it by Sitecore will best give you only a “prettier” URL, and the added disadvantage of having to add another 302 redirect to the same page after you checked with the redirect has a built-in language or not. Ruud’s suggestion of using IIS rewriting is good.

, - 301 Google, ( , URL- i.e "en" ) ).

, Sitecore, cookie , . cookie.

  • sc_lang.
  • URL.
  • cookie, .
  • , .
  • DefaultLanguage, web.config.

Sitecores

, , Sitecore.Pipelines.HttpRequest.LanguageResolver cookie ( URL- ) cookie , . , .

- Google, , , , URL, (, , ).

<link rel="canonical" href="http://www.abc.com/en/xyz.aspx"/>
+2

, , URL- Sitecore, languageEmbedding="always" , URL- LinkManager:

Sitecore.Links.LinkManager.GetItemUrl(item);

URL- languageEmbedding , UrlOptions:

var options = Sitecore.Links.LinkManager.GetDefaultUrlOptions();
options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Always;
options.EmbedLanguage(Sitecore.Globalization.Language.Parse("en"));

Sitecore.Links.LinkManager.GetItemUrl(item, options);

, !

+1

Sitecore.Pipelines.PreprocessRequest.StripLanguage... , , en.

0

URLOptions , , . -

protected UrlOptions URLOptions
        {
            get
            {
                if (urlOptions == null)
                {
                    urlOptions = new UrlOptions()
                    {
                        LanguageEmbedding = LanguageEmbedding.Always,
                        AddAspxExtension = false
                    };
                }
                return urlOptions;

            }
        }

URloption geturl(), .

LinkManager.GetItemUrl(itm, URLOptions)

0

You can achieve this functionality with the sitecore parameter.

enter image description here

Please see the screenshot. Change languageEmbedding property always from asNeeded This parameter is executed in the Sitecore.config file. Please let me know if this helps you fulfill your requirements.

0
source

All Articles