Facebook crawler doesn't follow my rewrite rule - facebook

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.

Related

How to redirect from image path

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.

Facebook OpenGraph meta tags unread

My client updated me that Facebook sharing didn't work anymore on his website i made. I've been looking and testing many things and it seems that Facebook doesn't read those metas properly and triggers errors in the debugger. I've tried and read many times documentation, changed the attributes.
The website : http://www.celianemoller.fr
Facebook debugger : https://developers.facebook.com/tools/debug/sharing/?q=www.celianemoller.fr
The Facebook scraper debug returns an empty response, which is confusing.
Maybe you guys can see what i can't. Any input on this subject can be really helpful.
Here's a quick update : I had those DNS problems and resolved, but still problems getting meta datas from Facebook.
So i browsed here on stackoverflow on other answers made by #CBroe and i found that Facebook had problems with GZIP content encoded.
For those who encounter the same problems, here's an Apache Rule to handle this :
<IfModule mod_setenvif.c>
BrowserMatch facebookexternalhit no-gzip
</IfModule>
And i get the meta datas updated on Facebook debugger !

Facebook sharer 403 forbidden

I have a website in Joomla hosted on my own vps. I have installed plugin for meta og, but share on facebook still give an 403 error. I've checked the facebook debugger, and it's like it can not resolve the url (bad http response).
Other tools for social analysis of the page show me the page and the meta correctly, and other social sharer like google+ work good. Only facebook sharer is broken.
I have tried with gzip on and off, but still 403 forbidden.
Someone know how can i make it work?
Thanks in advance!
Ok, I solved this: there was a mod_security rule (protocol violations) that was blocking the sharer of Facebook. If I remove that rule, facebook sharing is ok.
So, I am not an expert of mod_security, but I don't think it's good thing to remove completely a security rule.. Do you know if it is possible to write a specific exception?

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 :)

URL full story not linking correctly need htaccess help?

I am linking some stories on FaceBook, but the url I have is:
http://webpage.com/single.php?2011/02/04/my-story-here.html
FaceBook linking doesn't like the ".php?"
Can I do something with my .htaccess page to make it like:
http://webpage.com/single.php/2011/02/04/my-story-here.html
???
Thanks in advance.
By the way, when you click the link in facebook it goes to this link:
http://webpage.com/single.php?2011%2F02%2F04%2Fmy-story-here.html
and doesn't show my full story :-(
If you have AcceptPathInfo activated in Apache, you can indeed do
http://webpage.com/single.php/2011/02/04/my-story-here.html
and fetch the part after the .php from the $_SERVER["PATH_INFO"] variable.