nextjs重定向slug通配符

发布于 2025-01-25 07:31:59 字数 764 浏览 1 评论 0原文

我想将REGEX匹配- \ d+的URL重定向到没有该字符串的URL。 这与最后一个sl一起使用,但对于先前的sl。

这是我的重定向代码:

  {
    destination: `/my-path/:slug*`,
    permanent: true,
    source: '/my-path/:slug*(-\\d+)'
  }

此URL:http:// localhost/my-path/subdir-one/subdir-two-123

成功地重定向到:http:// localhost/localhost/my-- path/subdir-one/subdir-two

但是,此URL:http://localhost/my-path/subdir-3456/subdir-two-two-123

不成功至:<代码> http:// localhost/my-path/subdir-oon-3456/subdir-two

我以为 *是匹配整个路径,并假定plo以每条路线应用于每条路线。

我在这里想念什么?

I'd like to redirect URLs that regex match -\d+ to a URL without that string.
This works with the last slug but for the ones prior.

This is my redirect code:

  {
    destination: `/my-path/:slug*`,
    permanent: true,
    source: '/my-path/:slug*(-\\d+)'
  }

This url: http://localhost/my-path/subdir-one/subdir-two-123

redirects successfully to: http://localhost/my-path/subdir-one/subdir-two

However this url: http://localhost/my-path/subdir-one-3456/subdir-two-123

redirects unsuccessfully to: http://localhost/my-path/subdir-one-3456/subdir-two

I thought the * was to match the entire path and assumed ???? the regex to be applied on every route.

What am I missing here?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文