使用启用了pushState的页面,通常可以使用escaped_fragment约定来重定向SEO机器人。您可以阅读有关 here 的更多信息。

约定假定您将在单个页面应用程序上的所有URI之前使用(#!)hashbang前缀。 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]

问题在于,随着广泛采用的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

重写规则可以使用此较新的约定将漫游器引导到您的缓存版本吗? Related but only accounts for index edge case. Google也 has an article ,建议在页面的<meta name="fragment" content="!">中使用<head>针对这种单边情况使用选择加入方法。同样,这是针对单边情况。在这里,我们正在谈论将每个页面作为选择加入处理。
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]

处理此问题的最佳方法是什么?

最佳答案

在单页Web应用程序上有类似的问题。

我发现此问题的唯一解决方案是有效地创建静态版本的页面,以使Google(和其他)漫游器可以浏览某些内容。

您可以自己执行此操作,但是也有一些服务可以做到这一点并为您创建静态缓存(并通过它们的CDN将快照提供给bot)。

我最终使用了SEO4Ajax,尽管还可以使用其他类似服务!

关于javascript - .htaccess用于SEO机器人爬网单页应用程序而没有hashbangs,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17926219/

10-12 00:06
查看更多