【发布时间】: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