html - 将 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" />
?
解决方案
在彻底查看Context
变量后,我发现该Request.Url.AbsolutePath
属性确实与您所在页面的路径有关。您可以使用该属性在<link rel="alternate" href="@string.Format("https://www.example.com{0}", absoluteUrlPath)" hreflang="en" />
具有匹配页面的其他相应语言中反映您所在的页面。
推荐阅读
- google-sheets - 根据条件组合值,使用 Arrayformula | 谷歌表格
- java - 春季从 oracle db 授权为其他用户
- javascript - 在按钮单击时动态更新样式,D3 条形图
- colors - Tailwind CSS 扩展了 tailwind.config.js 中的标准颜色。当我尝试扩展颜色时,所有其他颜色都被删除
- java - 类的“set”方法应该返回“void”还是“boolean”?
- python - 使用类来计算python中条目列表的平均值
- xml - 在 TestNG 中运行测试后,IntelliJ 未创建 failed.xml 文件
- javascript - e.target.dataset 两次没有给出相同的值 - Javascript
- python-3.x - 无法再将 Snowflake 连接器与 Big Sur 一起使用:错误找不到库安全性
- rust - 为另一个特征实现和使用特征