How to redirect from image path - facebook

I'm using the Facebook Sharer snippet to allow users to share a specific post to their Facebook page. It's sharing a dynamic image passed into the FB Sharer (not the main url), so the image is www.site.com/path/to/image.jpg - when the user clicks on it from the actual Facebook post, as expected, it routes to that www.site.com/path/to/image.jpg.
My question is can I set up a redirect to ALWAYS send to the index.html page whenever the www.site.com/path is hit? I was thinking I could use javascript to redirect, but you can't fire javascript on a .jpg page. Is this an htaccess thing? If so, I have no idea how to go about that either. I am using Amazon S3 with Cloudfront.
Here is the FB Sharer -
window.open(http://www.facebook.com/sharer.php?u=${root}&t=${title})
This is working correctly, but looking for help on how to redirect any page that has a /path/ after www.site.com

This could work - you need to exclude the Facebook Crawler:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteRule ^path/to/([^.]+\.(jpe?g|gif|bmp|png))$ http://www.newurl.com [R=301,L,NC]
Sources:
htaccess redirect all images to different location and put image name in new url
Exempt Facebook Crawler from .htaccess redirect
I tested it here: https://htaccess.madewithlove.be/
Although, the ideal/usual way is NOT to share images directly, but URLs with the image as og:image tag.

Related

Facebook sharing debugger gives 404

Can you please help me debug this! Whenever we are sharing content links from our website in facebook; its not working. Redirection to content works if I'm using desktop browser or directly opening the link in mobile browser. But from facebook in app browser I can see either its loading 404 page or the video doesn't play. What could be the reason behind this? Please check below link from here
Either redirect from http to https in general or change the og:image to https instead of http. If you enter the URL into the browser, you get redirected: http://www.bioscopelive.com/bundles/bongoweb/images/oglogo.jpg
You can also add og:image:secure_url as metatag with the https URL of the image.
Make sure that everything is public and not locked by gelocation or login. Facebook servers need to be able to reach the URLs.

Facebook crawler doesn't follow my rewrite rule

I have this in my HTACCESS:
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/1.1|Facebot|Twitterbot|Pinterest|Google.*snippet|/externalhit_uatext/)
RewriteRule /+(.*?)$ /api/getSocial.php?which=$1 [P]
And using the facebook debug tool with my website, I see that facebook is getting the url without being rewritten, which is very weird. This is the url:
http://lab.pre.rtve.es/carlos-v-ricardo/podcast/
¿Any ideas why the crawler is not following this redirect? ¿Has the name of the user agent changed for Facebook?
I can read in the official documentation that this should work.
Thank you very much.
In the https://developers.facebook.com/docs/sharing/webmasters/crawler it is also written the crawler can have the
facebookexternalhit/1.1
(+http://www.facebook.com/externalhit_uatext.php)
useragent, and you do not cover that.

Open Graph scraping base URL instead the URL it's given

The Facebook OpenGraph debug tool is scraping the wrong page.
If I give it a full URL (pointing to an individual page on my site) that I want it to scrape, instead of scraping that page and finding its meta tags, it scrapes my site's main page and returns those meta tags (which are obviously wrong in this context).
The weird thing is, it will even find and scrape my site's main page even if it's not located at the root of my domain. For example:
I want it to scrape http://mydomain.com/myhomepage/specific_page.html
Instead, it scrapes http://mydomain.com/myhomepage/
This implies to me that the error must be a setting someplace, either on my site or on my Facebook App settings. Would the App settings do that? Redirect to whatever URL is set if a requested URL is a descendent of it?
The URL I'm requesting is not doing a 302 or anything - I can click the link from the FB debug tool even and it will take me to the appropriate page.
A few notes:
specific_page.html is not an actual file, it is routed through index.php using mod_rewrite in Apache's htaccess. I tried being specific with http://mydomain.com/myhomepage/index.php/specific_page.html and it did not work then either.
Another SO question led me to believe that the user-agent might be getting redirected if it doesn't allow cookies (as the Facebook web crawler does not) so I opened a fresh browser, disabled cookies, tried again, and I still reached the appropriate page.
As mentioned in the comments above, in your case this was due to an og:url meta tag, redirecting Facebook's crawler to that URL
In general, cases like this are usually the og:url tag, a HTTP redirect, or a canonical meta tag pointing at the 'other' / 'wrong' URL - Facebook's crawler follows those redirects looking for the final URL

Open Graph URL is a permalink that redirects to page

I'm adding on my website the open graph meta tags and testing if it is working with the Facebook URL Linter.
The only thing that is not working how I would like it is the og:url: tag, in this meta tag I want to add the permalink url of the current page.
The permalink actually redirects to the current page. I use this because my URL of the pages looks like this : http://website.com/photos/243/hello-this-is-the-title/ and the last part of the URL can be changed be the user and if it is changed the URL will change and it will not be associated with all the "Likes" stored at Facebook.
This is why I have a permalink page that looks like this : http://website.com/permalink/243/ and this will redirect to http://website.com/photos/243/hello-this-is-the-title/, so that all the likes on Facebook are associated with the permalink instead of the other one.
When I use the Facebook URL linter it tells me that there are some critical errors that need to be fixed - Circular redirect path detected (see 'Redirect Path' section for details).
I don't know if what I want to do is possible. But I could really use a little help here.
This is why I have a permalink page that looks like this : http://website.com/permalink/243/ and this will redirect to http://website.com/photos/243/hello-this-is-the-title/, so that all the likes on Facebook are associated with the permalink instead of the other one.
When I use the Facebook URL linter it tells me that there are some critical errors that need to be fixed - Circular redirect path detected (see 'Redirect Path' section for details).
Two options:
Exclude the Facebook scraper from being redirected, by looking for it’s user agent (details).
Don’t redirect server-side, but do it client-side via JavaScript instead. (The scraper does not care about JavaScript.)

Facebook like button adds query strin to the url

i am implementing the facebook like button, and specified for it the url to like,
when i click on the LIKE button, in facebook i saw the correct page the liked, but when i click on the link there
the link is what is specified in the code with some odd facebook querystring appended.
for exmpl:
the page that i like is
http://www.mydomain.com/path/to/the/page
when i clicked on the liked link in facebook, the url is:
http://www.mydomain.com/path/to/the/page?fb_action_ids=#####&fb_action_types=og.likes&fb_source=timeline_og&action_object_map={"###"%###}&action_type_map={"###"%3A"og.likes"}&action_ref_map=[]
and the page is not loaded correctly, is this is a facebook fault?
Use the xfbml or html5 version of social plugin and include in your metatag this
<meta property="og:url" content="...." />
Facebook adds various parameters to the URL so you can track where the visits are coming from etc. Its probably your page that doesn't work with these parameters, rather than facebook. Ideally, you page should just ignore these parameters if you don't need them.
I solved this problem by defining the URL in the fb:like button as well as in the og:url.
<fb:like href="http://www.yourwebsite.com/yourfullurl.html" send="true" layout="button_count" width="300" show_faces="false"></fb:like>
Now regardless of the parameters sent back from FB it seems to honor the count.
We can remove/strip the appended query string with the help of .htaccess file.
Place the code mentioned below in your .htaccess file:
RewriteCond %{QUERY_STRING} fb_action_ids=.*$
RewriteRule .* %{REQUEST_URI}? [R=301,L]
RewriteCond %{QUERY_STRING} fb_comment_id=.*$
RewriteRule .* %{REQUEST_URI}? [R=301,L]
This will do the trick :)