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

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.

0

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

^https?://([^.]+\.)*exampledomain\.com

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.