Skip to content

Instantly share code, notes, and snippets.

@stackcoder
Created October 19, 2015 20:13
Show Gist options
  • Save stackcoder/e2ac967c40e4bd30c57b to your computer and use it in GitHub Desktop.
Save stackcoder/e2ac967c40e4bd30c57b to your computer and use it in GitHub Desktop.
Generates a .htaccess file to block referer spam based on https://github.com/piwik/referrer-spam-blacklist.
#!/bin/bash
# wget https://raw.githubusercontent.com/piwik/referrer-spam-blacklist/master/spammers.txt -O spammers.txt
{
echo -ne 'RewriteEngine On\n\n' && \
echo '# denied referers' && \
cat spammers.txt | head -n -1 | sed 's/\./\\\./g' | sed 's/^\(.*\)$/RewriteCond "%{HTTP_REFERER}" "\1$" [NC,OR]/' && \
cat spammers.txt | tail -n 1 | sed 's/\./\\\./g' | sed 's/^\(.*\)$/RewriteCond "%{HTTP_REFERER}" "\1$" [NC]/' && \
echo 'RewriteRule .* - [F]'
} > referer.htaccess
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment