You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Vercel.json中实现特定URL带/不带尾斜杠的重定向?

解决Vercel中带/不带尾斜杠的URL重定向问题

要实现/docs/api/graphql/dam/overview/introduction和/docs/api/graphql/dam/overview/introduction/这两个路径的永久重定向,你可以简化原有的正则规则,直接匹配带或不带尾斜杠的目标路径:

正确的vercel.json配置

{
  "redirects": [
    {
      "source": "/docs/api/graphql/dam/overview/introduction/?",
      "destination": "/developers/docs/apis/asset-management/overview",
      "permanent": true
    }
  ]
}

配置说明

  • source中的/?表示末尾的斜杠是可选匹配,这样就能同时命中带尾斜杠和不带尾斜杠的两个URL。
  • 如果你需要匹配introduction后面还带任意子路径的情况(比如/introduction/subpage或/introduction/subpage/),可以把规则调整为:
    {
      "source": "/docs/api/graphql/dam/overview/introduction(/.*)?",
      "destination": "/developers/docs/apis/asset-management/overview",
      "permanent": true
    }
    
    这里的(/.*)?表示匹配可选的斜杠加任意后续路径,覆盖所有以introduction开头的子路径(带/不带尾斜杠)。

注意事项

  • 确保规则放在redirects数组中(Vercel的重定向配置需要包裹在这个数组内,原代码片段可能遗漏了外层结构)。
  • 测试时可以用Vercel CLI的vercel dev命令本地验证重定向是否生效,避免直接部署后出现问题。

内容的提问来源于stack exchange,提问作者Snivio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 23:20:44