Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm using the following code to block referrer spam on a site which is receiving a huge volume of spam traffic.

I'm told that it is more efficient in terms of server load to use httpd.conf, but I'm largely unfamiliar with this type of operation and haven't found much in the way of tutorials specific to the situation. Could anyone help with tutorials or resources showing similar methods of blocking referring domains?

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} spammer-one\.com [NC,OR]
RewriteCond %{HTTP_REFERER} spammer-two\.com
RewriteCond %{HTTP_REFERER} spammer-three\.com
RewriteRule .* - [F]

In addition is it worth investing the time in blocking via httpd.conf, will it significantly reduce server load compared to the htaccess code above?

share|improve this question

2 Answers 2

You can try SetEnvIf Referer, something in the lines of:

SetEnvIf Referer spammer-one\.com spammers
SetEnvIf Referer spammer-two\.com spammers
SetEnvIf Referer spammer-three\.com spammers

...

Order Allow,Deny
Allow from all
Deny from env=spammers

in your vhost definition/httpd.conf file.

Further reading:

http://httpd.apache.org/docs/2.0/mod/mod_setenvif.html#setenvif

http://httpd.apache.org/docs/2.0/mod/mod_access.html

share|improve this answer

if you want server-wide, then you can use this in your httpd.conf:

<Directory /var/www/vhosts/*/httpdocs>

SetEnvIf Referer spammer-one\.com spammers
SetEnvIf Referer spammer-two\.com spammers
SetEnvIf Referer spammer-three\.com spammers

Order Allow,Deny
Allow from all
Deny from env=spammers
</Directory>

Replace /var/www/vhosts/*/httpdocs with the correct path on your server. The wildcard "*" does work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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