Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block referral traffic from multiple referrers and subdomains in .htaccess file?

I'm seeing thousands of referrals coming from Russia and China every month from the domains below, I've tried adding the code below to my .htaccess file, and then testing it from another domain I own, but I don't appear to be getting the 403 Forbidden message I'm expecting to get. What am I missing?

RewriteCond %{HTTP_REFERER} ^(www\.)?([a-z0-9-]+)\.social-buttons\.com$ [NC]
RewriteCond %{HTTP_REFERER} social-buttons\.com [NC]
RewriteCond %{HTTP_REFERER} googlsucks\.com [NC]
RewriteCond %{HTTP_REFERER} 4webmasters\.org [NC]
RewriteCond %{HTTP_REFERER} aliexpress\.com [NC]
RewriteCond %{HTTP_REFERER} best-seo-solution\.com [NC]
RewriteCond %{HTTP_REFERER} best-seo-offer\.com [NC]
RewriteCond %{HTTP_REFERER} buttons-for-website\.com [NC]
RewriteCond %{HTTP_REFERER} www\.myothertestdomain\.com [NC]
RewriteRule .* - [F]
like image 806
Robert82 Avatar asked Dec 11 '22 00:12

Robert82


1 Answers

Your current code means:

If referer is "sociel-buttons.com"
AND
If referer is "googlsucks.com"
AND
etc...

Which is not what you want (always false: that's why it never happens).
Instead, you have to use OR flag (you want OR boolean conditions in your case)

RewriteCond %{HTTP_REFERER} ^(www\.)?([a-z0-9-]+)\.social-buttons\.com$ [NC,OR]
RewriteCond %{HTTP_REFERER} social-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} googlsucks\.com [NC,OR]
RewriteCond %{HTTP_REFERER} 4webmasters\.org [NC,OR]
RewriteCond %{HTTP_REFERER} aliexpress\.com [NC,OR]
RewriteCond %{HTTP_REFERER} best-seo-solution\.com [NC,OR]
RewriteCond %{HTTP_REFERER} best-seo-offer\.com [NC,OR]
RewriteCond %{HTTP_REFERER} buttons-for-website\.com [NC,OR]
RewriteCond %{HTTP_REFERER} www\.myothertestdomain\.com [NC]
RewriteRule ^ - [F]
like image 127
Justin Iurman Avatar answered Dec 27 '22 05:12

Justin Iurman