0

I am trying to ban some bots by writing a RewriteCond rule in htaccess file. Is the following ruleset correct if I add the following:

## block traffic from particular referrers
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(www\.)?example-subdomain.parent.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?example-2-domain.net [NC]
RewriteRule (.*) - [F]

As you see I wish to ban by domain name and not by IP address. Is it OK if I remove the (www.) part?

Update: My question is mainly related to RewriteCond correct syntax for the urls.

Thanks

developer
  • 535
  • 2
  • 8
  • 15

2 Answers2

0

Yes. You could replace "http://(www\.)?" with ".*" as long as you don't expect that domain name to appear elsewhere in legitimate referer strings. I'd also suggest putting .* after the .com or .net in case any slashes or paths get tacked on there.

g491
  • 973
  • 5
  • 7
0

If you know the parant domain and want to block it and all of its sub-domains:

^https?://([^.]+\.)*exampledomain\.com
Chris Lam
  • 283
  • 1
  • 9