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

能否为AWS Amplify的403错误配置自定义页面?

AWS Amplify 配置自定义404/403错误页面

当然可以配置自定义错误页面来替换默认的XML 403响应,具体操作分两种方式:

方式一:通过Amplify控制台配置

  • 登录AWS Amplify控制台,打开你的应用
  • 进入App settings > Rewrites and redirects
  • 点击Add rule,添加一条重定向规则:
    • Source address: </^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$)([^.]+$)/>
    • Target address: /404.html
    • Type: 404 (Rewrite)
  • 保存规则,部署更新后,访问不存在的页面就会跳转到你自定义的404.html

方式二:通过amplify.yml配置文件设置

在项目根目录的amplify.yml文件中,找到frontend配置块,添加errorPage字段指定自定义错误页面路径:

frontend:
  phases:
    preBuild:
      commands:
        - npm install
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: dist # 根据你的项目构建产物目录调整
    files:
      - '**/*'
  errorPage:
    - target: /404.html
      statusCode: 404

保存后提交代码到Amplify关联的仓库,触发自动部署即可生效。

注意:如果你的站点是单页应用(SPA),上述重写规则也能同时解决前端路由的刷新问题,确保所有非资源请求都指向入口文件(比如index.html);如果是纯静态站点,只需指定自定义404页面即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 15:25:22