Last Updated on May 27, 2021 by Amit

Block bad referer domains using htaccess

Last night when I checked my friend’s domain on ahrefs tools I was amazed to see the backlink profile of his domain. He had a bad SEO backlink profile, domain with just 2.5 DR even with 125 referering domains and 1600 backlinks.
When I analyzed the backlink profile , I saw some strange random spam domains . There were multiple domains with the same name and with different extensions pointing to my friends domain.
The main reason why the domain ratting decreased was the bad referer domains using the backlink. When I checked further I noticed there were 97 raferer domains with 0 DR and 0UR (UrlRatting). DR “Domain Ratting” is the domain trust score. DR can be anything from 0 to 100 . The less the DR the less trusted domain it is. If your domain has 0 DR then your chances of ranking in search engines are lower. DR increases when a domain with good DR points to your domain .

But if a bad domain (bad domain is a domain with 0 DR/UR or it can be a domain flaged as spam by search engines) points to your domain , it can decrease your domain ratting and prevent your domain from being indexed by search engines. So it’s always important to take care of your referer domains and backlinks. You can use free backlink checker tool to keep an eye on your backlink profile.

Block bad referer domains using htaccess

To block bad referer domains the best and the easiest option is RewriteRule .
Just create a list of referer Domains you want to block and use RewriteRule in htaccess to redirect those domain to 403 forbidden error page. By using a 403 redirect those domains won’t be able to redirect traffic to your site and you can improve your damaged backlink profile .

To block a single referer domain , you can use the following code in your htaccess :

RewriteEngine on
RewriteCond %{HTTP_REFERER} baddomain\.com [NC]
RewriteRule .* - [R=403,L]

Make sure to replace baddomain.com with the domain name you want to block.

If you want block referering domains, you can use the exact same Rule with [OR] conditions.
The following rule blocks 3 referer domains , if you have more domains you can tweak the code accordingly . But just keep in mind that you don’t have to use OR flag with the last condition :

RewriteEngine on
RewriteCond %{HTTP_REFERER} baddomain\.com [NC,OR]
RewriteCond %{HTTP_REFERER} baddomain2\.com [NC,OR]
RewriteCond %{HTTP_REFERER} baddomain\.com [NC]
RewriteRule .* - [R=403,L]

With the rules shown above you can easily block bad referers from your website.

I hope this article was helpful. Thanks so much for reading.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.