在NextJS中重定向通配符路线
在部署新的NextJS应用程序时,需要从旧的非nextjs网站保存一些旧路线。
/const-string- [longiqu-hash]
当前用于HTTPD Conf Redirect:
ex。 重写 ^const-string - (。*)$ https://google.com?q=const-string-qure-quly-qur-quny1 [l,nc]
我如何保留NextJS路由,但允许遗留路由匹配路径:/const-string - *
?
所需的行为:
/blog
路由pages/blog.js
/const-string-a1b2c3d4
路由到https://google.com ?q = const-string-a1b2c3d4
当前行为(到目前为止仅Local-Host测试):
/blog
路由pages/blog.js
按预期工作/const-string-a1b2c3d4
路由到404
在重定向到404之前,如何捕获匹配该字符串的URL?
In deploying a new NextJS app there are some legacy routes that need to be preserved from the old, non-NextJS site.
/const-string-[long-unique-hash]
is used currently for a httpd conf redirect:
Ex. RewriteRule ^const-string-(.*)$ https://google.com?q=const-string-$1 [L,NC]
How can I preserve NextJS routing, but allow for legacy routes matching the path: /const-string-*
?
Desired behavior:
/blog
routespages/blog.js
/const-string-a1b2c3d4
routes tohttps://google.com?q=const-string-a1b2c3d4
Current behavior (only localhost testing so far):
/blog
routespages/blog.js
works as expected/const-string-a1b2c3d4
routes to404
How can I catch urls matching this string before it's redirected to 404?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于可能希望这样做的其他人,我最终使用自定义404.JS文件来处理这样的重定向。
页面/404.js
:For others that may wish to do the same, I ended up using a custom 404.js file to handle redirects like this.
pages/404.js
: