【问题标题】:django sitemap.xml documentation contradicts with the original sitemap documetationdjango sitemap.xml 文档与原始站点地图文档相矛盾
【发布时间】:2020-11-18 19:52:28
【问题描述】:

我正在使用内置站点框架为我的 django 项目创建站点地图。

我有一个带有get_absolute_url 方法的模型,通过url 名称使用reverse

默认情况下,没有任何自定义/配置,我得到了这种站点地图:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2020-07-29</lastmod>
    <changefreq>hourly</changefreq>
    <priority>0.8</priority>
  </url>
  <url>
    <loc>https://example.com/subdomain/</loc>
    <lastmod>2020-07-29</lastmod>
    <changefreq>hourly</changefreq>
    <priority>0.8</priority>
  </url>
</urlset>

嗯,这就是我开始耸耸肩的地方。

引用django's sitemap documentation:

位置

可选。方法或属性。

如果它是一个方法,它应该返回给定对象的绝对路径,由 items() 返回。

如果它是一个属性,它的值应该是一个字符串,代表一个绝对路径,用于 items() 返回的每个对象。

在这两种情况下,“绝对路径”是指不包含协议或域的 URL。例子:

好:'/foo/bar/'

错误:'example.com/foo/bar/'

不好:'https://example.com/foo/bar/'

但是从上面的示例中可以看出,默认情况下,协议和域都包含在 sitemap.xml 的loc 标记内。

引用自相矛盾的Sitemap Documentation

必需
页面的 URL。如果您的 Web 服务器需要,此 URL 必须以协议(例如 http)开头并以斜杠结尾。此值必须少于 2,048 个字符。

所以,假设我正在做 SEO 并尝试使用适当的站点地图提高我的网站在谷歌搜索中的排名,我应该在两种风格之间选择什么?

【问题讨论】:

    标签: django seo xml-sitemap


    【解决方案1】:

    我会选择 'https://example.com/foo/bar/'..这是 xml 站点地图的正确完整网址,正如 Google 在此处建议的那样https://developers.google.com/search/docs/advanced/sitemaps/build-sitemap#expandable-1

    【讨论】:

      猜你喜欢
      • 2018-07-22
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      相关资源
      最近更新 更多