3

在我目前正在开发的网站上,我们进行了以下设置:

  • Angular JS 前端
  • IIS 上的 ASP.NET MVC Web API 后端
  • Prerender.io 缓存服务

在 web.config 中使用以下重写规则:

<rule name="AngularJS" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{URL}" pattern="^/sitemap.xml" negate="true" />
        <add input="{URL}" pattern="^/robots.txt" negate="true" />

        <add input="{QUERY_STRING}" pattern="_escaped_fragment_" negate="true" />
        <add input="{HTTP_USER_AGENT}" pattern="facebook" negate="true" />            
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>

我们在 index.html 中有 <meta name="fragment" content="!">,AngularJS 在启用 HTML5 pushstate 的情况下运行,后端有一个 HttpModule 可以接收具有 _escaped_fragment 或适当的请求UserAgent 并呈现 Prerender.io 内容。

使用常规搜索引擎爬虫,这可以按预期工作 - 在 prerender.io 中,我们可以看到爬虫请求正确的 url 并获得适当的缓存内容。

但是,对于 Facebook,无论我使用什么 URL 在https://developers.facebook.com/tools/debug/og/object/prerender.io上进行测试,都会要求提供根页面(即https://example .com/ )

现在,我已经通过将 Facebook 从 IIS 重写中排除来修复它

        <add input="{HTTP_USER_AGENT}" pattern="facebook" negate="true" />            

但是,我不知道为什么 Google 能够通过我当前的设置访问正确的页面,而 Facebook 却不能?我在某处读到 301 和 302 的处理方式可能不同,这可能是使用重写而不是重定向的情况吗?

4

0 回答 0