如何在 Next.js 中添加站点地图而不使用任何 npm 包?

发布于 2025-01-20 15:43:52 字数 674 浏览 3 评论 0原文

我通过创建一个名为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

enter image description here

Next.js Pages Folder:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找我们的幸福 2025-01-27 15:43:52

pages 文件夹下添加的文件应为 JavaScript /TypeScript 文件,其中包含生成页面所需的代码。

要静态提供 sitemap.xml 文件,您应该将其移至 public 文件夹。

来自静态文件服务文档:

Next.js 可以在名为的文件夹下提供静态文件,例如图像
根目录中的public

(...) 此文件夹对于 robots.txtfavicon.ico、Google 也很有用
站点验证以及任何其他静态文件(包括 .html)!

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 the public folder instead.

From the Static File Serving documentation:

Next.js can serve static files, like images, under a folder called
public in the root directory.

(...) This folder is also useful for robots.txt, favicon.ico, Google
Site Verification, and any other static files (including .html)!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文