【发布时间】:2013-09-11 17:02:03
【问题描述】:
我正在尝试使用大量客户端 Jquery/AJAX 魔术创建一个完全托管在 CouchDB 上的整个站点(也没有 nginx 反向代理)。现在我正在使它对 SEO 友好。我正在使用虚拟主机和 URL 重写将流量从根路由到我的 index.html 文件:
虚拟主机:
example.com /dbname/_design/dd/_rewrite/
在我的重写定义中:
rewrites:[
{
"from": "/db/*",
"to": "/../../../*",
"query": {
}
},
{
"from": "/",
"to": "../../static/index.html",
"query": {
}
}
]
When optimizing a site for SEO, Google requires you to do a few things:
- 在您的友好 URL 中使用井号 (#!) 告诉网络爬虫您是一个具有网络可爬取材料的 AJAX 站点:
http://example.com/index.html#!home - 使用 http 查询参数提供该 AJAX 页面的 HTML 转义片段:
http://example.com/index.html?_escaped_fragment=home
我尝试了以下方法,但没有成功:
rewrites:[
{
"from": "/db/*",
"to": "/../../../*",
"query": {
}
},
{
"from": "/",
"to": "../../static/index.html",
"query": {
}
}, /* FIRST ATTEMPT */
{
"from": "/?_escaped_fragment=:_escaped_fragment",
"to": "/_show/escaped_fragment/:_escaped_fragment",
"query": {
}
}, /* SECOND ATTEMPT */
{
"from": "/?_escaped_fragment=*",
"to": "/_show/escaped_fragment/*",
"query": {
}
}, /* THIRD ATTEMPT */
{
"from": "/",
"to": "/_show/escaped_fragment/:_escaped_fragment",
"query": {
}
}
]
据我所知,CouchDB 的 URL 重写器无法区分带 args 和不带 args 的 URL。有没有人幸运地通过 CouchDB URL 重写创建了这样的规则?
【问题讨论】:
-
您的第三次尝试是唯一正确的。只需查询
/_design/ddoc/_rewrite?_escaped_fragment=foo,它将被重写为/_design/ddoc/_show/escaped_fragment/foo。当然,您需要在这种情况下定义escaped_fragment显示函数。 -
@Kxepal 第三个选项的唯一问题是 CouchDB 将其视为与我将“/”发送到“../../static/index.html”的重写规则相同。跨度>
-
是的,碰撞。可以合并它们吗?在这种情况下,
:_escaped_fragment将是undefined(_rewrite/->_show/escaped_fragment/undefined),但您会注意到他在查询对象中丢失了,因此应该很容易从 show 函数再次重定向到 @ 987654335@(不是很好,但仍然是解决方案) -
我曾考虑过使用重定向,但 Google 规范规定它必须是完全相同的 URL 才能使网站可抓取:
http://example.com/index.html#!home和http://example.com/index.html?_escaped_fragment=home。如果我重定向到与http://example.com/index.html不同的地方,我最终会得到一个新的 URL(追逐我的尾巴)。 -
顺便说一句,我可能无法找到解决这个问题的方法,但我找到了 SEO 的 hashbang/escaped_fragment 方法的潜在替代方法:moz.com/blog/…