Developer forum

Forum » Rapido » RFC: hreflang in rapido

RFC: hreflang in rapido

Siv Hansen
Siv Hansen
Reply

The world is getting smaller and internalization is important to alot of our customers. With that in mind, the hreflang-attribute is important for both their customers and SEO. I can't find this feature in DW/Rapido - hence this RFC.

My suggestion is that whenever a site has a language layer, DW displays the following on every page with a translation

canonical = current page

x-default = fallback page in case no language layer exists for the user browser

alternative = all translations of the current page, including the current page

I'd like the option of choosing values for hreflang as both language and language+region/country

Pretty please. 


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Siv,

I recently had to do this myself for one of our projects.

Here is the code you can put in your Master.cshtml template. You can choose what you need.

<html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName">
<head>
<meta charset="utf-8" />
<title>@Model.Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<!--Alternate Pages-->
@if (Model.Languages.Count > 1)
{
foreach (var lang in Model.Languages)
{
var qs = HttpUtility.ParseQueryString(System.Web.HttpContext.Current.Request.QueryString.ToString());
qs.Set("ID", lang.Page.ID.ToString());
string url = "Default.aspx";
foreach (string key in qs)
{
var value = qs[key];
url = url.Contains("?") ? string.Format("{0}&{1}={2}", url, key, value) : string.Format("{0}?{1}={2}", url, key, value);
}
string alternateLink = "http://" + lang.PrimaryDomain + Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(url);
<link rel="alternate" hreflang="@lang.Culture.ToLower()" href="@alternateLink"/>
}
}
 
@Model.MetaTags
<!-- Favicon -->
<link href="@favicon" rel="icon" type="image/png">

 

You must be logged in to post in the forum