DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Build Blacklist .htaccess File Modified

  • submit to reddit
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Get the entries from a blacklist
and print them to standard output
import urllib2, re
latest = urllib2.urlopen("")
prefix = 'RewriteEngine  on'
suffix = 'RewriteRule /(.*) / [F,L]'
str = [prefix]
begin = "RewriteCond %{HTTP_REFERER} ^.*"
for line in latest:
	print '.',
	str.append(begin + re.sub('(\s#:url:|\s#:regex-url:|\s#:rbl:)', ".*$ [OR,NC]", line))
file('.htaccess', 'w').write('\n'.join(str))

Use of list to speed up.

Added prefix and suffix to make it a complete rewrite.