我正在使用
next-sitemap
包来创建站点地图。
我有动态和静态页面。
这是我的
next-sitemap.config.js
文件:
module.exports = {
siteUrl: 'https://example.com',
generateRobotsTxt: false,
exclude: ['/server-sitemap-index.xml'], // <= exclude here
robotsTxtOptions: {
additionalSitemaps: [
'https://example.com/server-sitemap-index.xml', // <==== Add here
],
},
}
但是此配置生成两个站点地图。
robots.txt
:
Sitemap: https://example.com/sitemap.xml
以上链接内容:
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<script/>
<sitemap>
<loc>https://example.com/sitemap-0.xml</loc>
</sitemap>
<sitemap>
<loc>https://example.com/server-sitemap-index.xml</loc>
</sitemap>
</sitemapindex>
sitemap-0.xml
是静态链接,server-sitemap-index.xml
是动态链接。
但我只想有一个站点地图,例如:
https://example.com/sitemap.xml
static links
....
dynamic links
根据他们的文档,您可以选择不使用多个站点地图 -
📣 从 next-sitemap v2.x 开始,sitemap.xml 将成为索引站点地图。 它将包含所有其他生成的站点地图端点的 URL。
可以通过设置关闭索引站点地图生成 generateIndexSitemap:下一个站点地图配置文件中为 false。 (这是 对于不需要索引站点地图的小型/爱好网站很有用) (示例:无索引站点地图)
generateIndexSitemap: false
谢谢这件事对我来说确实有用。 生成索引站点地图:假 现在我的公共文件夹中只有一个文件包含我的所有网址。
像这样:“http://localhost:3000/sitemap.xml”