Mobile app version of vmapp.org
Login or Join
Sarah324

: Mike, I think the easiest, and first place, I would start is to modify your Layout (.aspx) such that pages using an alias have the <link rel="canonical" href="..."/> in the head. You

@Sarah324

Mike,
I think the easiest, and first place, I would start is to modify your Layout (.aspx) such that pages using an alias have the <link rel="canonical" href="..."/> in the head.

You can leverage code provided with this answer to help you.

Essentially, add a asp:Literal to the <head> of your .aspx page. Now, on Page_Load of your .aspx.cs you can do the following

if (global::Sitecore.Configuration.Settings.AliasesActive && global::Sitecore.Context.Database.Aliases.Exists(System.Web.HttpContext.Current.Request.RawUrl))
{
const string format = "<link rel="canonical" href="{0}://{1}{2}"/>";
global::Sitecore.Data.Items.Item targetItem = global::Sitecore.Context.Database.GetItem(global::Sitecore.Context.Database.Aliases.GetTargetID(System.Web.HttpContext.Current.Request.RawUrl));

canonicalLiteral.Text = string.Format(format, "http", System.Web.HttpContext.Current.Request.Url.Host, global::Sitecore.Links.LinkManager.GetItemUrl(targetItem));
}


Note, you may need to adjust that based on the configuration of your LinkManager.

10% popularity Vote Up Vote Down


Login to follow query

More posts by @Sarah324

0 Comments

Sorted by latest first Latest Oldest Best

Back to top | Use Dark Theme