By Sheryl Canter
You can block distracting, privacy-invading Web site ads with tools that come with your computerno need to buy a thing. One way is by editing the Windows HOSTS file (see "Block Web Ads" at http://go.pcmag.com/blockwebads). A less-known but more powerful method is through a Proxy Automatic Configuration (PAC) file, a feature of all modern browsers. Why would you want to use these do-it-yourself methods rather than simply buy inexpensive software that does it automatically? One reason is you like getting your hands dirty and learning how things work. Another is you might find this gives you more configuration options, letting you more easily customize the ad blocking.
Both HOSTS and PAC files block ads by redirecting ad server requests, but HOSTS files can only block entire sites, while PAC files can block URLs within a site. This is important because some companies that serve ads also serve content you would not want to block. For example, the ad server akamai.com also provides streaming media for many Web sites, including Microsoft, for whom it handles Windows Updates. If you block akamai.com, you won't be able to access Windows Updates.
HOSTS files have other limitations. Because each ad server is listed separately, HOSTS files can get so long that they slow the system. PAC files can be much shorter because they support regular expressions (strings that describe whole sets of strings via wildcards and special characters). HOSTS files are bypassed on systems using proxy servers, but PAC files are not. If your computer is running a Web server, there are problems in redirecting ads with a HOSTS file that don't exist with a PAC file.
The blocked sites in this PAC file are redirected to port 3421 of localhost (your own computer) so as not to conflict with any Web servers that might be running on port 80. Redirecting to an unused port like 3421 causes no problems for IE or Mozilla, but Opera will complain that there is no proxy at that address.
To appease Opera, you can run a small, single-purpose Web server that responds to ad requests with a transparent bitmap. This also serves to eliminate the unsightly error messages that appear when the ads aren't found and prevents delays in browsers that take a while to time out when content isn't found.
Blackhole Proxy, written by Larry Wang, does just this. Version 1.0, just released, features an install utility and a configuration program, so you don't have to learn command line options. You can download it free, with source code,
To use Blackhole Proxy with a HOSTS file, you must change the port from the default of 3421 to 80. Blackhole Proxy is unique in its ability to configure the port. Also, since it can accept connections from other computers, it can be shared on a network.
Once you have Blackhole Proxy loaded, you can configure your browser to use the PAC file. In IE, open Internet Options from the Tools menu, select the Connections tab, then click on Settings or LAN Settings, depending on how you connect to the Internet. In the resulting dialog, check the box Use automatic configuration script, and enter the filename with a syntax like file://C:/PacFiles/ad-block.pac. Then below that, check the box for using a proxy server. In the Address field, type 127.0.0.1 (the IP address for localhost), and for Port enter 3421.
If you're using Internet Explorer, you have to change two additional settings. First, click on the Security tab, select Local intranet, click on the Sites button, and uncheck the box labeled Include all sites that bypass the proxy server.
Second, you must turn off the auto proxy caching mechanism, which prevents the restriction of some server content while allowing other content. Microsoft didn't provide an interface to this setting, but you can use a clever .REG (Registry) file, written by Bill Talcott (www.schooner.com/~loverso/no-ads/IE-auto-proxy-cache.reg), that lets you change the option and add a check box for it on the Advanced page of the Internet Options dialog.
Last but not least, remember to clear your browser's cache after setting up your PAC file. If you don't, the ads will be retrieved from your cache.