背景:我有一个博客,其中包含大量被 Google 索引的内容。例如,所有内容都被索引为www.site.com/post1。我正在将我的博客迁移到 NextJS,并且我已将博客文章的范围限定为www.site.com/blog/post1。我能够轻松地使用 301 重定向来维护这些博客文章的 SEO。但是,我遇到了一个问题,其中www.site.com/sitemap.xml 之类的链接也被重定向到www.site.com/blog/sitemap.xml。只有当模式与某些路径不匹配时,有没有办法重定向?这是我在 next.config.js 中关于重定向的部分
async redirects() {
return [
{
source: '/:slug',
destination: '/blog/:slug',
permanent: true// Matched parameters can be used in the destination
},
{
source: '/sitemap.xml',
destination: '/sitemap.xml',
permanent: false// Matched parameters can be used in the destination
}
]
}