首页 > 解决方案 > 将 HREFLANG 标签关联到当前页面

问题描述

我的任务是更新我们的 hreflang 标签以与用户所在的网站相关联。例如...

目前它是硬编码的,<link rel="alternate" href="https://www.example.com/" hreflang="en" />但是说用户已经导航到products/tabletimes页面,所以 URL 实际上是https://www.example.com/products/tabletimes. 有没有办法对标签进行编码<head>以反映这一点?

因此,它可能是<link rel="alternate" href="https://www.example.com/products" hreflang="en" />和/或<link rel="alternate" href="https://www.example.com/products/tabletimes" hreflang="en" />

标签: htmlseohrefhead

解决方案


在彻底查看Context变量后,我发现该Request.Url.AbsolutePath属性确实与您所在页面的路径有关。您可以使用该属性在<link rel="alternate" href="@string.Format("https://www.example.com{0}", absoluteUrlPath)" hreflang="en" />具有匹配页面的其他相应语言中反映您所在的页面。


推荐阅读