So, how to Block Spammy Referrers? If you’ve noticed strange websites appearing in your analytics reports or getting unusual traffic from unknown sources, chances are you’re dealing with referrer spam. Spammers send fake traffic to your site to boost their own rankings, manipulate search engines, or trick website owners into visiting their sites.
Referrer spam doesn’t just clutter your analytics; it can also slow down your website, waste server resources, and, in some cases, harm your SEO. If left unchecked, it can create misleading traffic data, making it harder to analyze real visitor behavior.
The good news? You can block spammy referrers using multiple methods, from server-side rules to security plugins. In this guide, we’ll walk you through how to stop referrer spam and protect your website from unwanted traffic.
Use .htaccess (For Apache Servers)
If your website is on an Apache server, you can block spammy referrers by adding this code to your .htaccess file:
apacheCopyEditRewriteEngine on
RewriteCond %{HTTP_REFERER} spammydomain\.com [NC,OR]
RewriteCond %{HTTP_REFERER} another-spamsite\.com [NC]
RewriteRule .* - [F]
Replace spammydomain.com
and another-spamsite.com
with the actual spam domains you want to block.
Block Spammy Referrers via Nginx
For Nginx servers, add the following lines to your nginx.conf file inside the server
block:
nginxCopyEditif ($http_referer ~* (spammydomain\.com|another-spamsite\.com)) {
return 403;
}
This will return a 403 error (Forbidden) to any request coming from those domains.
Use Google Analytics Referral Exclusions
To filter out spam referrers from your analytics reports:
- Go to Google Analytics → Admin → Tracking Info → Referral Exclusion List
- Add the spammy domains to prevent them from affecting your reports.
Block at the Firewall Level
If spam traffic is heavy, use a firewall service like:
- Cloudflare (Firewall Rules → Block specific referrer URLs)
- Sucuri
- Your hosting provider’s built-in firewall
Use WordPress Plugins (If Using WordPress)
If you run a WordPress site, install a security plugin like:
- Wordfence (Blocks bad bots and spam referrers)
- All In One WP Security & Firewall
Report Spam Domains to Google
You can also report spam sites abusing your domain via Google’s Spam Report Tool to prevent their influence on search rankings.
Referrer spam might seem like a minor annoyance, but if ignored, it can distort your analytics and even affect your website’s performance. By taking proactive steps like blocking spammy referrers, filtering them out in analytics, and strengthening your site’s security you can keep your data clean and your website safe. Stay vigilant, update your spam filters regularly, and focus on what truly matters: growing your site with genuine traffic and meaningful engagement.