I saw that my website is receiving spam traffic from floating-share-buttons.com, Get-Free-Traffic.com, event-tracking.com, forum.topic64300434.darodar.com, etc. automatically. I searched on google and found a way to block this using htaccess file. The code I found is below -
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://.*ilovevitaly\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*ilovevitaly.\.ru/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*ilovevitaly\.org/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*ilovevitaly\.info/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*iloveitaly\.ru/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*econom\.co/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*savetubevideo\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*kambasoft\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*buttons\-for\-website\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*semalt\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*floating\-share\-buttons\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*Get\-Free\-Traffic\-Now\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*event\-tracking\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*darodar\.com/ [NC]
RewriteRule ^(.*)$ – [F,L]
I want to know whether this code is best solution or not. The author of this code was saying that this code will block the spam traffic. I want to know whether it will or not? Is there any better solution? And what actually this code does with the spam bots?
No, it isn't the solution, that code won't work for most of the referrals on that list. The only ones that will be blocked using the htaccess file are
semalt and buttons-for-websitefor the rest it won't have any effect.We can split the spam in Google Analytics in 2 categories the Ghosts that only hit Google Analytics reports and never accesses your site and the Crawlers that as the name implies crawl your site therefore they do access.
Since Ghost spam doesn't interact with your website at all any server-side solution like the htaccess won't have any effect. To stop Ghosts you must use filters in GA
You can find detailed information in this related questions.
https://stackoverflow.com/a/28354319/3197362
https://stackoverflow.com/a/31270950/3197362