Home > Tutorials > HTACCESS Tutorials > Block Referrals From Specific Domains

Block Referrals From Specific Domains

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
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_REFERER} domain1\.com [NC,OR]
 RewriteCond %{HTTP_REFERER} domain2\.com [NC,OR]
 RewriteRule .* - [F]
</ifModule>

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.

About 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.

Check Also

HTACCESS Tutorials

Welcome to the .htaccess tutorials section of the Rapid Purple blog. The following tutorials are ...

Like every other website, this site uses cookies to analyze our traffic. Cookies may also be utilized by our advertisers and partners. By using this website you agree to the use of said cookies. More Information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings, continuing to navigate past this message, or you click "Accept" below then you are consenting to the use of cookies on the Rapid Purple website.

Close