Dan*_*nze 7 javascript .htaccess web-crawler single-page-application
使用pushState
启用的页面,通常您使用escaped_fragment
约定重定向SEO机器人.你可以在这里阅读更多相关信息.
该约定假定您将#!
在单个页面应用程序上的所有URI之前使用()hashbang前缀.SEO机器人会escaped_fragment
在发出页面请求时用它自己可识别的约定替换hashbang来逃避这些片段.
//Your page
http://example.com/#!home
//Requested by bots as
http://example.com/?_escaped_fragment=home
Run Code Online (Sandbox Code Playgroud)
这允许站点管理员检测机器人,并将它们重定向到缓存的预渲染页面.
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
RewriteRule ^(.*)$ https://s3.amazonaws.com/mybucket/$1 [P,QSA,L]
Run Code Online (Sandbox Code Playgroud)
问题在于,随着广泛适应的pushState
支持,hashbang正在逐步淘汰.它也非常丑陋,对用户来说不是很直观.
那么如果我们使用HTML5模式,pushState引导整个用户应用程序呢?
//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
Run Code Online (Sandbox Code Playgroud)
可以使用这个较新的约定重写规则引导机器人到您的缓存版本吗?相关但仅考虑索引边缘情况.谷歌也有一篇文章是建议使用一个选择,在方法使用这种单边的情况下<meta name="fragment" content="!">
在<head>
页面.同样,这是针对单边案例的.在这里,我们讨论的是将每个页面作为一个选择性的 Senario处理.
http://example.com/?escaped_fragment=
http://example.com/category?escaped_fragment=
http://example.com/category/subcategory?escaped_fragment=
Run Code Online (Sandbox Code Playgroud)
我认为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]
Run Code Online (Sandbox Code Playgroud)
处理这个问题的最佳方法是什么?
在单页网络应用程序上也有类似的问题。
我发现这个问题的唯一解决方案是有效地创建页面的静态版本,以便谷歌(和其他)机器人可以导航。
您可以自己执行此操作,但也有一些服务可以完全执行此操作并为您创建静态缓存(并通过其 CDN 向机器人提供快照)。
我最终使用了 SEO4Ajax,尽管还有其他类似的服务可用!