【问题标题】:Subdirectory pages not found static site hosted on Google Cloud Storage Bucket未找到托管在 Google Cloud Storage Bucket 上的静态站点的子目录页面
【发布时间】:2019-12-09 02:03:55
【问题描述】:

我正在使用 Loadbalancer 在 Google Cloud Storage Bucket 上设置一个静态站点。该站点由 Gridsome 生成,然后 dist 文件夹保存在存储桶中。

我已经在 [文档] 中使用 gsutil 设置了索引和错误:https://cloud.google.com/storage/docs/gsutil/commands/web

现在我面临一个问题,即每个用于访问子目录的 url 如何被重定向到 dir/index.html。这是期望的行为, dir/index.html 页面甚至存在于存储桶中。但我仍然收到 404 - 未找到。

如果我对 url subdir/index.html 进行 curl 我会得到 HTML

【问题讨论】:

    标签: google-cloud-platform google-cloud-storage gridsome


    【解决方案1】:

    基于 GCS 上的 How subdirectories work,当浏览器请求 URL http://www.example.com/dir 时,它将被重定向 (301) 到所服务内容上的对象 http://www.example.com/dir/index.html

    我的假设是 Vue (vue-router) 上没有路由 http://www.example.com/dir/index.html。所以它会被抛出到 Not Found 404 页面。

    简单的解决方案是尝试更改所有子目录链接

    http://www.example.com/dirhttp://www.example.com/about 等,到

    http://www.example.com/dir/, http://www.example.com/about/

    当您请求子目录 url 或重新加载浏览器时,它不会重定向到 404 页面。但我们都知道这不是最佳做法。

    【讨论】:

      【解决方案2】:

      我不知道你是如何测试你的子文件夹的,但我认为这个链接可以帮助你解决你的问题Error 404 when loading subfolder on GCS。另外,你也许必须看看这里How subdirectories work

      【讨论】:

      • 当我卷曲到 subdir/index.html 它返回 HTML。它只是一个托管在存储桶上的静态站点,不能在那里使用 app.yaml!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 2021-01-16
      • 2023-03-23
      • 2021-05-23
      相关资源
      最近更新 更多