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

Vercel URL重写配置问题:如何将/html/contact映射为/contact?

解决Vercel自定义域名URL重写问题
  • 修正vercel.json的重写规则
    你当前的rewrites规则搞反了source和destination的逻辑:source是用户实际访问的URL路径,destination是服务器内部对应的文件路径。你想要的是用户访问/contact时,实际加载/html/contact.html(因cleanUrls: true可省略.html),所以正确配置如下:

    {
      "cleanUrls": true,
      "rewrites": [
        {
          "source": "/contact",
          "destination": "/html/contact"
        }
      ]
    }
    
  • 调整HTML跳转链接
    直接将a标签的href改为期望的路径即可,不需要再指向旧路径:

    <a href="/contact">Contact</a>
    
  • 可选:旧路径跳转优化(SEO友好)
    如果希望用户访问旧路径/html/contact时自动跳转到新路径/contact,可以在配置中添加redirects规则:

    {
      "cleanUrls": true,
      "rewrites": [
        {
          "source": "/contact",
          "destination": "/html/contact"
        }
      ],
      "redirects": [
        {
          "source": "/html/contact",
          "destination": "/contact",
          "permanent": true
        }
      ]
    }
    

    permanent: true会返回301永久重定向,对SEO更友好。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 16:35:20