2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http(s)?://([^.]+\.)*tumblr\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http(s)?://([^.]+\.)*nometoqueslashelveticas\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http(s)?://([^.]+\.)*webnuz\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http(s)?://([^.]+\.)*ihgz\.tk [NC]
RewriteRule .* - [F]
</IfModule>

I'm not particular familiar with htaccess, so hoping someone might be able to confirm/deny if this code is correct?

Simply looking to deny access to multiple spammy domains that are back linking to my posts and pages.

What confuses me is that some of the domains have different TLD's, some start with a sub domain, some are HTTP or HTTPS, www or not www, so trying to make sure that the code covers all those variables, as the examples:

http://www.ttyifu.com 
https://www.hostmds.com
http://blog.hostmds.com 
https://arsiv.pilli.com
http://green-ch.info/

Found a few examples of this code that have the OR tag after the NC, so assuming this is correct, but that the last line doesn't have the OR.

  • "deny access to multiple spammy domains that are back linking to my posts and pages" - What are you hoping to achieve here? – MrWhite Sep 28 at 0:52
1

Simply looking to deny access to multiple spammy domains that are back linking to my posts and pages.

What you are proposing here (blocking access based on the HTTP Referer) is not going to "deny access to multiple spammy domains" the way I think you think it will.

In fact, as the webmaster of the site being linked to, you can't programmatically ...

  • Prevent a site from linking to your site.
  • Prevent that link from being seen by the search engine bots as a do-follow link. (Search engine bots generally do not send an HTTP Referer header as part of the request when they crawl your site... at least Googlebot does not.)

At best, this will simply prevent a real user from following a link from the spammy website to your site. But the spammy website can even work around this and prevent the user-agent sending the Referer, by employing the Referrer-Policy.

Where did you get this list of spammy domains from? Have you confirmed that these sites are indeed linking back to your site and you are not simply seeing the results of referrer spam in your logs? (The HTTP Referer header is trivial to fake.)

If these really are spammy backlinks and you think Google is likely to serve a negative action against your site ranking then consider submitting these links to Google's Disavow tool - this is the only way to prevent these links being counted towards your backlink profile (for Google at least). However, for trivial/obvious spam links this is probably not necessary.

Reference:
https://support.google.com/webmasters/answer/2648487?hl=en


To answer your specific questions relating to the syntax of these directives:

What confuses me is that some of the domains have different TLD's, some start with a sub domain, some are HTTP or HTTPS, www or not www, so trying to make sure that the code covers all those variables

You need to match against the specific domain the link is coming from. Create multiple rules to cover multiple variations if you wish (if the spammy site does not canonicalise the hostname) or combine using a regular expression - as in your earlier example:

RewriteCond %{HTTP_REFERER} ^http(s)?://([^.]+\.)*tumblr\.com [NC,OR]

For example, the above condition matches HTTP or HTTPS and any number of subdomains of tumblr.com, including no subdomain at all. So, any of the following, and more...

  • http://tumblr.com
  • https://tumblr.com
  • http://sub.tumblr.com
  • https://sub.sub.tumblr.com

The parentheses in ^http(s)?:// are not necessary and should simply be removed. ie. ``^https?://. The parentheses result ins` being captured in a backreference, which is not being used here.

Found a few examples of this code that have the OR tag after the NC, so assuming this is correct, but that the last line doesn't have the OR.

Yes, that is correct. If you included an OR flag (not a "tag") on the last condition, then it would unconditionally block every request!

The NC (nocase) flag is only to catch bot traffic that might send a mixed/uppercase hostname. All mainstream browsers lowercase the hostname when making the request.

Reference:
https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond

The <IfModule> wrapper is not required. Unless you are intending to use the same code on multiple servers that might not have mod_rewrite enabled and it is OK for these directives not to function.

Code of this nature is typically used for hotlink protection (not for preventing spammy backlinks). ie. Preventing other sites leaching off your static resources (typically images).

  • 1
    Aha, ok yes. What you say makes perfect sense, all of it. I was under the impression I could limit access to spammy domains by denying access, but obviously that's not the case. I've subsequently added my spam domain list to Google Disavow instead, so will focus on that method. I really appreciate the detailed explanations to the formatting of the code, and that all helps me understand what it does/doesn't do. – The Logo Smith Sep 29 at 11:39
  • Yes of course. Done and done. Have printed this out and bookedmarked. – The Logo Smith Sep 30 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.