: 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
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.
More posts by @Sarah324
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.