【发布时间】:2021-12-28 07:13:58
【问题描述】:
我使用 docusaurus 建立了一个网站,效果很好,但是当我在 google 上检查我的网站的索引状态时,我遇到了很多“已发现 - 当前未编入索引”的问题,这似乎是一个路由问题。
docusaurus 网站的编译版本会在单独的文件夹中为 docusauus 项目中的每个页面或 md 文件生成一个“index.html”文件,但生成的链接不会添加“index.html”,而是像这样结束: https://cam-inspector.com/contact。浏览器似乎没有转到“https://cam-inspector.com/contact/index.html”,而是使用根 index.html 页面并似乎在本地处理路由。这适用于查看,但谷歌爬虫只能查看根目录,因此每个页面都包含“https://cam-inspector.com”的规范网址。当您直接浏览到“https://cam-inspector.com/contact/index.html”时,将从服务器检索到正确的文件,并且规范标签对“https://cam-inspector.com/contact”是正确的'。
我尝试向谷歌应用引擎部署的 yaml 文件添加重定向,以便它将“index.hmtl”添加到所有不以文件扩展名结尾的路由,但这似乎不起作用:
handlers:
# for url without extensions, needs to go to index.html to get seo correct
- url: /(?:/|^)[^./]+$
static_files: www/\1/index.html
upload: www/(.*)/index.html
# files with extension, needed to get all the files
- url: /(.*\..+)$
static_files: www/\1
upload: www/(.*\..+)$
# Catch all handler to index.html, needed to get the root
- url: /.*
static_files: www/index.html
upload: www/index.html
在这篇文章中:app.yaml : Redirect any URL ending with / to {url}/index.html 他们似乎说您不能将这样的重定向添加到 yaml 定义中。
所以现在我有点卡住了,我唯一能想到的就是在 docusaurus 代码中的所有链接中添加“/index.html”,但这会产生一些非常难以维护和棘手的问题(尤其是使用自动生成的文档侧边栏,更改链接要困难得多)。
有关如何解决此问题的任何想法?
【问题讨论】:
-
您是说
/contact/index.html具有正确的规范标签,但/contact/没有? -
如果您创建站点地图并将站点地图提交到 Google 搜索索引会怎样?此外,您编写代码以在访问站点地图时自动生成站点地图,然后生成站点地图将包括自动将“index.html”添加到您拥有的每个网址的末尾?
-
@StephenOstermiller 是的,就是这样
标签: reactjs google-app-engine url docusaurus