How to block visitors by referrer domain using htaccess? Print

  • htaccess, mod_rewrite, apache
  • 2

Being a website owner, you might have seen a lot of traffic coming from external websites to your website. Some of these traffic aren't profitable or useful for you anymore, they just cause more server usage & cause website slowness/lagging issues. The below code blocks any & all visitors coming from a domain name that you have added; you should place the code inside .htaccess file where your domain name is pointed to.
#BLOCKING BELOW DOMAIN NAME FROM SENDING TRAFFIC TO OUR DOMAIN NAME 
RewriteEngine on 
RewriteCond %{HTTP_REFERER} externaldomain\.com [NC,OR] 
RewriteCond %{HTTP_REFERER} www\.externaldomain\.com 
RewriteRule .* - [F]
[NC] tells server not to take domain name as case-sensitive. OR lets you add another domain name within same code, we have added www instead.

Was this answer helpful?

« Back

Powered by WHMCompleteSolution