【问题标题】:How to use sitemap in firebase hosting with react app如何在带有 React 应用程序的 Firebase 托管中使用站点地图
【发布时间】:2018-11-25 02:15:08
【问题描述】:

我已经在我的 firebase 主机上部署了一个 reactjs 网络应用。我将 sitemap.xml 文件添加到公用文件夹中。我编辑了firebase.json 将源路由到sitemap.xml:

"redirects": [
      {
        "source": "/sitemap",
        "destination": "/sitemap.xml",
        "type": 302
      }
    ],
"rewrites": [
  {
    "source": "/*",
    "destination": "/index.html"
  }
]

但是当我去https://blah blah.com/sitemap时,它总是返回index.html,我也尝试将它添加到重写中,但它似乎总是返回index.html

我也在使用React Router 4 进行路由,也许这会影响这个。

<Switch>
        <Route component={Login} exact path="/login" />
        <Route component={Home} path="/home" />
        <Route component={About} path="/about" />
        <Route component={Carousel} path="/carousel/:galleryRef/:ref" />
        <Route component={RelayEditPage} path="/edit/:galleryRef" />
        <Route path="/" render={() => <Redirect to="/home" />} />
      </Switch>

如何将站点地图添加到托管域?如果我在Switch 中添加Redirect 组件,它可以工作,但是由于重定向,我无法设置谷歌搜索控制台站点地图。

【问题讨论】:

  • 尝试从firebase.json 中删除对sitemap.xml 的任何引用。由于您在那里存在一个静态文件,因此应该根据hosting priorities 返回
  • @abraham 感谢您的回复。我已经删除了所有引用,但是当我执行 domain.com/sitemap.xml 时,它总是回退到 / 并加载主页。
  • 如果我在 localhost 上运行它,它如何工作。只有 Firebase 主机总是将我重定向到“/”
  • 它在我的实验中运行良好。 ExampleSource.
  • @abraham 你能提供你的 firebase.json 托管部分的 sn-p 吗?

标签: reactjs firebase sitemap firebase-hosting google-search-api


【解决方案1】:

这对我有用:

"redirects": [
  {
    "source": "/sitemap",
    "destination": "/sitemap.xml",
    "type": 301
  },
  {
    "source": "/sitemap/**",
    "destination": "/sitemap.xml",
    "type": 302
  }
] 

【讨论】:

    【解决方案2】:

    我和你有同样的问题。使用以下配置使我的公共文件夹(包括站点地图)中的文件在部署后可以在线访问:

    "rewrites": [
      {
        "source": "/",
        "destination": "/index.html"
      },
      {
        "source": "/sitemap",
        "destination": "/sitemap.xml"
      }
    ]
    

    【讨论】:

      【解决方案3】:

      尝试删除 index.html 文件。 我创建了一个网站,其中我从公共文件夹中删除了 index.html,而是在函数文件夹中使用了 index.js。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-09-19
        • 1970-01-01
        • 2020-11-25
        • 1970-01-01
        • 2014-12-24
        • 2018-06-23
        • 2019-07-03
        相关资源
        最近更新 更多