如何在 Next.js 中添加站点地图而不使用任何 npm 包?
我通过创建一个名为stitemap.xml
的新文件,将我的站点地图添加到了下一个。
但是,当我尝试使用http:// localhost:3000/stitemap.xml
访问我的站点地图时,它会抛出404页,找不到错误。我需要将我的SiteMap文件URL添加到Google搜索控制台。那么,我如何解决此问题或在Next.js中添加stitemap.xml
的任何不同方法?
stitemap.xml
next.js pages文件夹:
I have added my sitemap to the Next.js pages
folder by creating a new file called sitemap.xml
.
But when I try to access my sitemap by using the http://localhost:3000/sitemap.xml
it throws a 404 page not found error. I need to add my sitemap file URL to Google Search Console. So how am I solving this problem or has any different method to add sitemap.xml
in Next.js?
sitemap.xml
Next.js Pages Folder:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pages
文件夹下添加的文件应为 JavaScript /TypeScript 文件,其中包含生成页面所需的代码。要静态提供
sitemap.xml
文件,您应该将其移至public
文件夹。来自静态文件服务文档:
Files added under the
pages
folder are expected to be JavaScript/TypeScript files with the code necessary to generate a page.To statically serve your
sitemap.xml
file, you should move it to thepublic
folder instead.From the Static File Serving documentation: