【问题标题】:Serving index.html to the Google bot with ?_escaped_fragment_=使用 ?_escaped_fragment_= 将 index.html 提供给 Google bot
【发布时间】:2013-07-01 11:38:24
【问题描述】:

我有一个非常繁重的 Javascript 应用程序,我希望将其编入索引。我的网站上有一个快照目录,可以提供给 Google 机器人。这些在mysite.com/snapshots/ 下。

我正在使用以下重写规则将快照提供给 Google 机器人:

location / {
    if ($args ~ "_escaped_fragment_=") {
        rewrite ^/(.*)$ /snapshots/$1.html break;
    }
}

这适用于我的所有快照,除了主页。问题是,主页被保存为mysite.com/snapshots/index.html。当 Google bot 请求 mysite.com/?_escaped_fragment_= 时,nginx 尝试为 /snapshots/.html 提供服务,显然是请求 404。

当请求文档根目录时,我需要调整重写规则以提供 index.html。

干杯!

【问题讨论】:

    标签: c nginx rewrite googlebot


    【解决方案1】:

    在重写行上方添加:

    rewrite ^/$ /index.html;
    

    【讨论】:

      【解决方案2】:

      将其添加到您的服务器配置中,无论在哪里,就在 server{} 内。

      location ^= index\.html$ {
          try_files $uri =404;
      }
      

      这会检查请求的 URL 是否以 index.html 结尾。如果这不起作用,我需要完整的 URL,因为 Google bot 会请求它们。

      【讨论】:

        猜你喜欢
        • 2014-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-20
        • 2017-02-21
        相关资源
        最近更新 更多