Htaccess Block or deny visitors by referrer

Sometime you want to stop traffic that coming from some sites, so you need to block or deny visitors by using their referrer, the best solution is to use htaccess, Apache Web Server enables us to do that in a simple way.

The following code will block any visitor by referrer:

RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} domain_name\.com [NC]
RewriteRule .* - [F]

Make sure that the mod_rewrite is enabled in your Apache server, we use RewriteCond to setup the condition for the redirect that will be made, RewriteRule is to set the target of the redirect, the sentence Options +FollowSymlinks is to prevent the server from displaying Error 500: Internal Server Error in some cases, the above code is to stop traffic from one domain, if you decided to prevent more than one domain, the code will be as the following:

RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} first_domain\.com [NC,OR]
RewriteCond %{HTTP_REFERER} second_domain\.com
RewriteRule .* - [F]

Note: be aware of editing your Htaccess file, any error in writing my cause Error 500, which will stop your site.

Comments
  1. No comments yet!, be the first to post a comment.

Your email will not be published, The required fields marked with '*'

*