Facebook bot may be a monster or a good crawl bot but I have to stop it from crawling my site and end its useless hits on my statcounter statistics record.
I visited my site statistics this morning only to discover a huge hits recorded by visits of Facebook bot. I knew quite well that facebook acts like search engines but I have never recorded such hits from any other search engine like Google so why should I be recording hits from facebook bot. Yes, I share posts directly from site to facebook but I also share post from my site to Google. Other people also do the same things.
The annoying part of it all is that, these facebook bot are even crawling my posts, even pages and giving huge hits that seem like visits from real person. The sight of those hits gives ugly impression on my blog stats, so I decided to find a way to stop the bot from crawling my site.
I searched throughout webpages of the net for information on how to stop facebook bot only to discover that there are little or no information on how to stop facebook bot.
After a long futile endless search, I came across some piece of information saying that the only way to stop facebook bot is to edit the .htaccess of my server and block those IP addresses of thefacebook bot. How would this be possible for someone who is not web programmer-tech and as there are hundreds of IP addresses used by this bot.
At the end I was able to figure out some codes that stop the facebook bot from crawling my blog.
Now, if you don’t like those hits from facebook bot, these are simple step to stop the bot from crawling you sites;
- On wordpress dashboard, locate appearance then editor.
- Click on editor and then header.php file
- On the header.php, locate <head>tag
- Place this code immediately after the opening <header> tag
<?php
$ua = $_SERVER[‘HTTP_USER_AGENT’];
if (preg_match(‘/facebookexternalhit/si’,$ua)) {
header(‘Location: no_fb_page.php’);
die() ;
}
- Clicks save to update your header.php file.
These will chess away the facebook bot from your site. No need creating a bots page.php on your website root directory and directing those bots there or editing your .htacess document file because there are hundreds of IP addresses used by this facebook bot unless you are web programmer guru, then you can do that.
If you try this and it works for you, don’t forget to share this page or link to it (you permitted to do so)
This is really helpful information, i was really looking for such great post.
I’m glad you found the article very helpful.
there is some issue with your theme try to post code in
Hello Tarun Kumar,
What is the issue?
i tried same but i dont think that is working ?
facebook bot is increasing load on our server
Hello Tarun Kumar,
But it works over here. Are you sure you copied the exact code and post it on the right section of your template
the code you shared have wrong single quotation , place it correctly , this is why its giving error
Thanks Tarun Kumar for your observation. I will do that later or you can just paste the right code here.
$ua = $_SERVER[‘HTTP_USER_AGENT’];
if (preg_match(‘/facebookexternalhit/si’,$ua)) {
header(‘Location: no_fb_page.php’);
die() ;
}
Ok, thank you for this.
Thank for the information man
You’re welcome,Raiser