Using .htaccess to block referrer spam
Web Hosting Articles »
A simple guide to .htaccess »
Using .htaccess to block referrer spam
Lately referrer spam became a great annoyance for the webmasters. If you are not sure what referrer spam is you may wish to check this article: http://en.wikipedia.org/wiki/Referrer_spam
To block these spam referrers you need the following lines in your .htaccess file:
# set the spam_ref variable
SetEnvIfNoCase Referer "^http://(www.)?some-spammer.com" spam_ref=1
SetEnvIfNoCase Referer "^http://(www.)?other-spammer.com" spam_ref=1
SetEnvIfNoCase Referer "^casino-poker" spam_ref=1
# block all referres that have spam_ref set
<FilesMatch "(.*)">
Order Allow,Deny
Allow from all
Deny from env=spam_ref
</FilesMatch>
The first lines “setenvifnocase” assign a span_ref environment variable. Then we deny all access to such referrers in the FilesMatch clause.
You can also use wildcards with the above .htaccess directives to match a variety of hosts. For example, you can use
SetEnvIfNoCase Referer "*some_word*" spam_ref=1
to match all referrers that contain the word 'some_word'.
For example you can ban visits from referral sites that contain in their domains words like: phentermine, viagra, cialis, shemale, porn, nude, celebrity, etc.
- How to block users from accessing your site based on their IP address
- How to prevent or allow directory listing?
- How to change the error documents – 404 Page Not Found, etc
- Using .htaccess for password protecting your folders
- Using .htaccess to block referrer spam
- Disable Hot-Linking of images and other files
- Redirect URLs using .htaccess
- Introduction to mod_rewrite and some basic examples
- Force SSL/https using .htaccess and mod_rewrite
- 301 Permanent redirects for parked domain names
- Enable CGI, SSI with .htaccess
- How to add Mime-Types using .htaccess
- Change default directory page
- Block Bad robots, spiders, crawlers and harvesters
- Make PHP to work in your HTML files with .htacess
- Change PHP variables using .htaccess
- HTTP Authentication with PHP running as CGI/SuExec
- Force www vs non-www to avoid duplicate content on Google
- Duplicate content fix index.html vs / (slash only)
Comments 2 >>
Sipylus Said,
Jan 19, 2010 @ 12:26
The "SetEnvIfNoCase" info was great and in a test was able to block of our site from google.com but not yahoo.com. | Previous: Using .htaccess for password protecting your folders | Next: Disable Hot-Linking of images and other files |

it's very helpful from me.
my website was flooded.