On a site I'm currently working on, we have the following set up:
- Angular JS frontend
- ASP.NET MVC Web API backend, on IIS
- Prerender.io caching service
With the following rewrite rules in the 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>
We've got the <meta name="fragment" content="!"> in index.html, AngularJS is running with HTML5 pushstate enabled, and there's a HttpModule on the backend that picks up requests that either have the _escaped_fragment or an appropriate UserAgent and renders Prerender.io content.
With regular search engine crawlers, this works as expected - in prerender.io, we can see the crawlers request the correct url and get served the appropriate cached content.
However, with Facebook, no matter what URL I use to test on https://developers.facebook.com/tools/debug/og/object/ prerender.io is being asked to serve the root page (ie https://example.com/)
For now, I've fixed it by excluding Facebook from the IIS Rewrite with
<add input="{HTTP_USER_AGENT}" pattern="facebook" negate="true" />
However, I am at a loss as to why Google would be able to hit the correct pages via my current setup, but Facebook does not? I read somewhere that 301 and 302 might be handled differently, is it possibly a case of using rewrites over redirects?