0

In a similar question it appears that the OP and comments were talking about a browser interaction with a server where URL fragments were not sent by a browser to the server.

My question: I have a site with pages that have URL fragments and some of them have images associated with them. I want to vary the Facebook og:image tag in the <head> of the page based on the URL fragment. Does the Facebook crawler send the fragment in an HTTP header or as a query param to the server?

We know that the browser will not send the URL fragment to the server. This question is specifically about the Facebook crawler (facebookexternalhit) which has the fragment and could send it as part of the full URL, in a header, or as a query parameter to the server.

Community
  • 1
  • 1
Guy
  • 65,082
  • 97
  • 254
  • 325
  • 1
    Test it …? Input such a URL in the debug tool, and see what info reaches your server. – CBroe Mar 28 '17 at 09:08
  • @CBroe - Thanks. I'll do that if I'm unable to find a documented technique for this. – Guy Mar 29 '17 at 12:59
  • Even if it did send the fragment, I am pretty sure that Facebook will still treat them as the same URL, so you would be presenting different OG meta data for the same URL all the time. So you would have to clear the cache every time, too, and if users refresh the share attachment in their posts later, it might also give unwanted results. This is not the way to go. See to it that you create unique URLs (meaning, not only different hash) for each image you want to share, and have those URLs redirect the human visitors that follow the links from Facebook to the actual target. – CBroe Mar 29 '17 at 13:04
  • So the unknowns here are (1) how FB crawler requests the page (i.e. does it include the fragment somewhere and (2) when FB crawler caches the page does it include the fragment as part of the unique key to identify that cached page or is it just the URL. I notice that FB has some intelligence somewhere in their pipeline because if you don't include the headers it will sometimes pickup the text at the fragment instead of using the text higher up so it has some awareness of fragments in auto-rendering summaries on its pages. – Guy Mar 31 '17 at 20:28
  • Yes, when you do not specify OG meta data at all, Facebook will analyze the URL's content and try and find suitable description and image(s). But even if they take into regard which part of the content a hash might refer to, I doubt they send it to the server. // Re: a technique for this, you would have to access the raw request headers somehow - but that might be tricky, http://stackoverflow.com/q/23446989/1427878, http://stackoverflow.com/q/165603/1427878 I'd perhaps start by checking the server's access log. – CBroe Mar 31 '17 at 20:37
  • @CBroe I logged the headers and url that come from facebookexternalhit (FB's crawler) and confirmed that the fragment is not sent in any manner. I think I'll have to provide unique URLs as well as the hash and then tag the URLs with a canonical URL that prevents the unique URLs from being indexed by search engines and then vary the og tags by unique URL. Thanks for brainstorming this with me! – Guy Apr 06 '17 at 21:23
  • @CBroe in case you're curious this is the change that I'm probably going to make: https://github.com/guyellis/plant/issues/990 – Guy Apr 06 '17 at 21:40

0 Answers0