Facebook fb_xd_fragment Problem – .htaccess Solution

FacebookSara was trawling through Google Analytics for our sites and noted that a number of posts showed their URL’s with an appended “?fb_xd_fragment=” like this:

http://sitename.com/postname/index.php?fb_xd_fragment=
http://sitename.com/postname/?fb_xd_fragment=

This is a known Facebook bug with the “Like button” and one that Facebook probably won’t resolve as it has been ongoing for quite a while now. It hasn’t been a huge problem for us and happens a negligible amout of times, for instance according to Google Analytics it happened on only 631 out of nearly 1.84 million pageviews on Geek Is Awesome in the past 30 days.

Still, that’s 631 times that users were confronted with a blank white screen and had to refresh, and 631 times that AdSense and other advertisers ads were shown but couldn’t be seen by the reader. 631 times too many in my book.

Eric Enge posted a solution over on Search Engine Land back in June, but I think this solution may be simpler and have just finished adding it to a number of our sites. Eric’s solution may be more complete in that it may work better on things like WordPress Network (multi-site) installs but this simple .htaccess solution should work for everyone else by doing a 301 redirect back to the post URL if the bug occurs.

Eric also noted that some of their posts were showing up in the search engine results with the “?fb_xd_fragment=” attached, which is of course a potential content duplication problem. We’ve not seen any results for our sites in the SERP’s with the fragment attached but this solution (found on the Webmaster World AdSense forum) should solve that too as it provides a 301 redirect for the fragment.

Anyhow, enough rambling, here’s the bit of code to drop in your .htaccess file.

#Redirect For Added FB Fragment
RewriteCond %{QUERY_STRING} ^fb_xd_fragment=.*$
RewriteRule ^(.*)$ http://yourdomain.com/$1? [R=301,L]

Hope this helps and remember that if you’re using something like WP Super Cache in WordPress don’t forget to hit the “update mod rewrite” rule button after adding the code so that it doesn’t throw that message at you telling you that a difference has been detected.

As always – you’re mileage may vary and any comments, questions and / or improvements are encouraged.