Alternative URLs in bilingual environment

Sylvain C. asked on March 5, 2020 00:51

I have 2 pages, one in English, one in Spanish. The alternative URL for the English page is en-us/staff and the alternative URL for the Spanish page is es-es/staff. It works well except when I change the culture of my website. Then, the URL of the page is based on the real one (/en-us/data/staff or /es-es/data/staff).

This is how I generate the buttons to change the culture:

 <a href="@Url.Action(                                                                  HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString(),                                                                    HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString(),
                                                                    currentRouteValues)">
                                                            @culture.CultureName
                                                        </a>

How can I make sure that the alternative URL is used and not the real URL?

Thank you

Sylvain

Recent Answers


David te Kloese answered on March 12, 2020 11:04 (last edited on March 12, 2020 11:05)

Hi,

The Alternative URL feature is NOT a replacement, it's used as an alternative way. Main purpose is to have a short campaign url for instance.

If you want to use the alternative URL you could get it via API:

AlternativeUrlInfoProvider.GetAlternativeUrls()
    .WhereEquals("AlternativeUrlDocumentID", yourpage.DocumentID)
    .ToList();

Note: that this can contain no (if not set) or multiple alternatives (when multiple are set). This is culture specific as you are using the DocumentID and not the NodeID

Alse remember that this can cause SEO issues if you don't redirect to the main URL. So you also might want to add Canonical tags.

see kentico docs for creating Providing canonical URLs for pages

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.