Simplified Ad Blocking
Posted on July 28th, 2007
About a year ago, I replaced the Squid proxy on my home network with Apache's mod_proxy. I wanted to continue blocking annoying ads on web pages without keeping an additional service running. It seemed like an obvious choice since Apache was already in the picture and ready to serve.
Things weren't all they were cracked up to be with mod_proxy. Setup and configuration took a lot of fiddling and fusing, and there was a bottleneck somewhere along the way that often made pages load more slowly. I had all sorts of URL rewriting power at my disposal, but not a solution that worked all the time, every time. So I scrapped the whole thing and did without.
Web page ads are still annoying though, and I still want to block them. Now I think I've got the right mix of simplicity and reliability. It's essentially the solution described at Superior Ad Blocking on OS X: add the hostnames of known ad servers to your hosts file, then configure Apache's ErrorDocument to return a blank page rather than the default message.
The one change I made was to point ErrorDocument to a 1x1 pixel GIF rather than an empty HTML page. This prevents broken image icons from appearing, and doesn't appear to create any problems with requests that expect to receive text.
I'm also adding the names of ad servers to my hosts file by hand, rather than grabbing one of the lists available from Wikipedia's page on the Hosts file. This way I'm only blocking the ad servers I've actually encountered, and not hundreds or thousands I'd never otherwise come across (if they're still in fact active).