There are many good reasons to want to remove banner ads with a local proxy. I've used Internet Junkbuster, SquidGuard and Privoxy successfully to do advert filtering in the past, but since I'm already running Apache, I thought it'd be worth investigating if I could use it instead. While this isn't as flexible as a dedicated ad-blocker like Privoxy, it might be of use on small machines.
This works by using
mod_rewrite to rewrite URLs which match
certain patterns so they point at a local file instead (an image which will
replace the advert). The patterns below block the adverts on most of the sites
that I regularly visit; you will get a few false positives, but I've tried to
avoid them as far as possible. If you come across an advert that the filter
doesn't catch, add a pattern that'll match it to the list (many graphical
browsers have some sort of "Copy image URL" function which is handy for
You'll need to copy my adfilter.conf file into your Apache configuration directory.
To filter adverts, enable
mod_proxy, and configure the proxy appropriately (you may want to
enable caching at the same time), then
"/wherever/adfilter.conf". Note that you must load
in order to get proxy requests to be rewritten. (This implies that you
have your Apache built with shared modules; the default module ordering
is the opposite of this, so you can't do advert filtering with a static
Modify the RewriteRule setting to point at your own replacement banner; I suggest making up your own in a typical banner size, or just using a 1x1 blank image. (Not that a 1x1 image can be anything other than blank, of course...)
Thanks to Ben Charlton and Chris Bryden for contributing blocking rules.
More information on blocking banner ads can be found at the Realtime Backhoe List.
Don Marti also has a much fancier version of Apache ad filtering, although some of his config files appear to be broken as I write...
Michael J. Talarczyk reported that if you're using Firefox (or
another Mozilla-family browser), you can significantly improve the
performance by increasing the
set to 4 by default, which means that Firefox will only have four
connections open per proxy.