Unfortunately these days not all traffic is good traffic – and as such the time may come when you may wish to block traffic that is coming from a certain referral domain. Firewall platforms such as Cloudflare have options for this available using their online dashboards – however you can accomplish the same thing without any fancy firewalls – simply using your .htaccess file!

In the following .htaccess tutorial that is exactly what we will be learning how to do.

# block visitors referred from indicated domains

 RewriteEngine on
 RewriteCond %{HTTP_REFERER} domain1\.com [NC,OR]
 RewriteCond %{HTTP_REFERER} domain2\.com [NC,OR]
 RewriteRule .* - [F]

This will block any visitors coming from domain1.com and domain2.com and show them a default error 403 page instead. You can add as many RewriteCond rules as you need to this script.

Published by Michael Boguslavskiy

Michael Boguslavskiy is a full-stack developer & online presence consultant based out of New York City. He's been offering freelance marketing & development services for over a decade. He currently manages Rapid Purple - and online webmaster resources center; and Media Explode - a full service marketing agency.

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *