Using a pushState
启用页面,通常您使用重定向 SEO 机器人escaped_fragment
习俗。您可以阅读更多相关内容here.
该约定假设您将使用 (#!
) hashbang 前缀位于单页应用程序上所有 URI 之前。 SEO 机器人将通过用自己可识别的约定替换 hashbang 来逃避这些片段escaped_fragment
当发出页面请求时。
//Your page
http://example.com/#!home
//Requested by bots as
http://example.com/?_escaped_fragment=home
这允许站点管理员检测机器人,并将它们重定向到缓存的预渲染页面。
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
RewriteRule ^(.*)$ https://s3.amazonaws.com/mybucket/$1 [P,QSA,L]
问题是,随着广泛的应用,hashbang 正在迅速被淘汰。pushState
支持。它也非常丑陋,并且对用户来说不是很直观。
那么如果我们使用 HTML5 模式,其中 pushState 引导entire用户应用程序?
//Your index is using pushState
http://example.com/
//Your category is using pushState (not a folder)
http://example.com/category
//Your category/subcategory is using pushState
http://example.com/category/subcategory
可以使用这个较新的约定重写规则引导机器人到您的缓存版本吗?相关,但仅说明索引边缘情况。谷歌也有一篇文章这建议使用opt-in对于这种单边缘情况的方法使用<meta name="fragment" content="!">
in the <head>
页面的。同样,这是针对单一边缘情况的。这里我们讨论将每个页面作为一个opt-in塞纳里奥。
http://example.com/?escaped_fragment=
http://example.com/category?escaped_fragment=
http://example.com/category/subcategory?escaped_fragment=
我认为escaped_fragment
仍然可以用作 SEO 机器人的标识符,并且我可以提取域和该标识符之间的所有内容以附加到我的存储桶位置,例如:
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$
# (high level example I have no idea how to do this)
# extract "category/subcategory" == $2
# from http://example.com/category/subcategory?escaped_fragment=
RewriteRule ^(.*)$ https://s3.amazonaws.com/mybucket/$2 [P,QSA,L]
处理这个问题的最佳方法是什么?