Blog Post: Web Technology
Remove unwanted query strings attached in posts shared from facebook comments plugin
Author:Sanjeev Maharjan

Most of you might have already been familar with many social plugin tools from Facebook. Like, Share, Recommend and Comment plugins are the most popular ones out there. These social plugins makes it so easy to share contents back and forth within your website and the most popular social network in town "FACEBOOK".

I too have been fascinated with the power of these plugins from Facebook and have been using them in most of my websites at work. However, the last plugin I used gave me some serious problem.

I recently implemented the comments plugin from Facebook to post comments to contents in our website. There were no hassles in implementing the plugin and posting comments using that plugin. The comments plugin allowed us to post comments to the facebook as well with the small checkbox which is checked by default.

Post To Facebook

So, whenever we post the comment, it shares the comment on your wall as well with a back-link towards the original link in your site. But the problem was, whenever it shared on your wall, Facebook automatically appends a 'fb_comment_id' as a querystring with some comment_id value. The original link on your wall will now look something like:

http://www.abc.com/a/b?fb_comment_id=12x_34y

The above URL in my case will generate a 404 error as, such query string is not desired so as to make our URL SEO-Friendly. Since, it is appended by Facebook itself, we cannot change it. So, whats the solution then?

The only solution I could think of was to redirect the URL discarding the querystring values. Since I am not expert in writing RewriteRule, I did what I am good at. I googled it Cool . And, finally I came up with a solution which goes like this:

#check for the query string with fb_comment_id

RewriteCond %{QUERY_STRING} (^|&)fb_comment_id

# redirect the url discarding the query string

RewriteRule ^(.*+)$ http://%{HTTP_HOST}%{REQUEST_URI}? [L,R]

For those who are new to URL Rewriting please refer to http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteRule

Hope this helps and save a lot of time for everyone facing the problem...



COMMENTS

No Comments Yet

Post a comment
* marked are required fields
*Name:
*Email Address:
*City:
*Comments
In order to help us prevent automated submissions, please type the number shown in below picture
*Validation no.
captcha
My Latest Tweets
Download Archive Here:
Twitter LinkedIn Blogger Behance Portfolio Facebook