Windows HOSTS File And WAMP
I used an .htaccess file for my webserver to display a PNG for certain domains in my HOSTS file.
Windows uses a file to speed up resolving host names, simply called the HOSTS file (no extension, although it's just a text file). For example, when your browser requests a file from www.google.com, it has to figure out the IP address of the server from which it's going to be getting the file. The browser will look in the HOSTS file to see if it has an IP listed for the domain for which you're looking. If it can't find anything, it looks up the domain using name servers and such. In short, the HOSTS file speeds things up. If on Windows NT/2000/XP it can be found in: C:\Windows\system32\drivers\etc\ (assuming you've installed Windows to the C: drive); if on OS X it's located in /private/etc; on *nix flavors it's usually located in /etc.
I scoured the Internet the other day looking for a HOSTS file to block advertisements, hoping that someone or some people had gotten together and created one, much like the community bands together for Firefox's Adblock extension to share lists and such. Luckily for me, I found one at http://www.mvps.org/winhelp2002/ The site even includes a batch file for installing it.
So now I have around 14,000 domains that simply link back to my own computer. While browsing I kept seeing 404 errors and it suddenly occurred to me: of course these advertisements aren't found on my computer. I do a lot of development work on my computer and run WAMP5 so I created an .htaccess file with a single line and dropped it in my http directory:
ErrorDocument 404 /404.png
Now whenever a site tries to load an advertisement (or really, any file) from any of the domains on my HOSTS list, it displays a 404 image from my own webserver. This is useful for blocking ads, malicious scripts, and all sorts of nasty stuff that the Internet can produce. Below is a link to the HOSTS file that I'm using.
Files
- HOSTS - This is the HOSTS file provided by http://www.mvps.org/winhelp2002/ (Last Updated 04-08-2007)