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 domainsRewriteEngine 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.
Leave a comment