angularjs - 在 AppEngine 的根路径上处理 _escaped_fragment_

标签 angularjs google-app-engine seo hashbang

我正在使用 Google App Engine 托管一个带有 Python 网络服务的 AngularJS 应用程序。根路径/设置为返回 index.html,/api/* 请求转到 Python Controller 以进行 Web 服务调用,任何其他路径转到静态资源(图像、 View 等)

我正在尝试使用 hashbang/_escaped_fragment_ 技术来为搜索引擎索引设置应用程序。据我了解,http://www.whatever.com/#!/news 的网址将被搜索引擎转换为 http://www.whatever.com/?_escaped_fragment_=/news

编写一些代码来处理该请求不是问题,但是让该代码在根路径上监听是一个问题,因为它已映射到 index.html

在发出 _escaped_fragment_ 请求时,是否有元标记或其他东西告诉搜索引擎使用不同的路径(不是/)?

如果没有,Google App Engine 是否有办法请求/提供 index.html,但如果存在 _escaped_fragment_ 查询参数,则转到 Controller 来处理请求?

目前,我发现唯一有用的是为根路径设置一个 Controller ,它会在其中检查 _escaped_fragment_ 参数。如果有,它会为搜索引擎呈现内容,如果没有,它会读取 index.html 并将其写入响应。我希望有更好的选择。

最佳答案

您只需将以下内容添加到您的页面,然后处理 www.example.com?_escaped_fragment_= :

<meta name="fragment" content="!">

来自 Google Developers for Making AJAX Applications Crawlable Getting Started教程:

换句话说,如果你放置<meta name="fragment" content="!">进入 www.example.com 页面,抓取工具会将此 URL 临时映射到 www.example.com?_escaped_fragment_= 并将向您的 服务器。然后你的服务器应该返回相应的 HTML 快照 到 www.example.com


同样来自 Full Specification页面,更具体地说,来自没有哈希片段的页面部分:

以下重要限制适用:

  1. 元标记只能出现在没有哈希片段的页面中。
  2. 只有“!”可能出现在内容字段中。
  3. 元标记必须出现在文档的头部。

关于angularjs - 在 AppEngine 的根路径上处理 _escaped_fragment_,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21433241/

相关文章:

javascript - 重用 ng-controller 作为单例

python - google-app-engine 全文搜索,哪个更好, "google custom search"或 whoosh

c# - 在 SEO Clean Uri 中删除的字符

node.js - yeoman angular generator 不会启动 grunt serve

javascript - 多语言应用程序中的 Angular JS 路由不起作用

javascript - 使用 JavaScript 加密模块代替 SSL/HTTPS

java、驱动 APIv2、appengine 1.7.3、struts2.3.4.1、OAuth2。 token 响应异常 : 400 OK invalid_grant

SEO:从谷歌中删除旧餐厅

php - 是否反对使用变量在另一个 View 中调用 View 的 MVC 模式?

javascript - 当在另一个模块中的另一个 Controller 上调用函数时,从模块更新 Controller 上的 $scope