我在我的firebase托管上部署了reactjs web应用程序。我将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>
如何将站点地图添加到托管域?如果我在Redirect
中添加Switch
组件它可以工作,但由于重定向我无法设置谷歌搜索控制台站点地图。
尝试删除index.html文件。我创建了一个网站,我从公共文件夹中删除了index.html,而是在functions文件夹中使用了index.js。
我遇到了和你一样的问题。使用以下配置,可以在部署后在线访问公用文件夹(包括站点地图)中的文件:
"rewrites": [
{
"source": "/",
"destination": "/index.html"
},
{
"source": "/sitemap",
"destination": "/sitemap.xml"
}
]
这对我有用:
"redirects": [
{
"source": "/sitemap",
"destination": "/sitemap.xml",
"type": 301
},
{
"source": "/sitemap/**",
"destination": "/sitemap.xml",
"type": 302
}
]