Disclosure: Hosting Canada is community-supported. We may earn a commission when you make a purchase through one of our links. Learn more.

Block the visitors through referrer

A website containing a link to your website is a referrer. When a page link of your website is followed by someone, then the site from where they come from is called as the referrer. Apache Web Server offers the facility to block visitors that allow you to deny the access of specific visitors on the basis of where they are coming. If you look at the logs and you notice an increase in your traffic surprisingly but with no increase in the actual file request, then most probably someone is pinching the content like the CSS files or doing hacking attempt on your website (this simply means to try to find the content that’s non public).

Enable ‘mod_rewrite’ on your server to use this functionality. Because of the demands in system resources, it’s not so likely that it’s enabled so ensure checking with your hosting company or system administrator.

For setting up a single referrer, you need to create an .htaccess file by following the guidance and the main instructions that include the text below.

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

Codes above will instruct Apache Web Server for blocking the traffic from ‘otherdomainname.com’ URL. The text ‘NC’ after it shows it isn’t case-sensitive. It stops traffic from ‘otherdomainname.com’, ‘OTHERDOMAINNAME.COM’, ‘OtherDomainName.com’, and so on.

For setting up multiple referrer blocks, you need to make an .htaccess file by following the guidance and main instructions that also includes that text below.

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

The lines above will tell an Apache Web Server to block the traffic from URL ‘anotherdomainname.com’ and ‘otherdomainname.com’. Note here that the backslash (\) placed before the ‘.com’ i.e, ‘domainname\.com’ is important. The difference between single referrer blocking and multiple referrer blocking is the [NC,OR] text in multiple referrer example above, it should be there after every domain only but not in the last one.

If you see the line above “Options +FollowSymlinks”, you can notice it is commented by hash ‘#’. If the server shows an error of ‘505 Internal Server’, then uncomment this line. It shows that in section ‘httpd.conf’, your server is not configured with FollowSymLinks. So, for getting advice on this issue, contact your system administrator.

The referrers blocked will get an error message of ‘403 Forbidden’. You can customize the 404 error following the above ‘’Document Errors’ part of this article.