Re: [SLUG] Ad blocking with hosts file and apache

From: PiousMinion (piousminion@gmail.com)
Date: Thu Mar 18 2010 - 17:37:42 EST


On Thu, Mar 18, 2010 at 4:22 PM, Paul M Foster <paulf@quillandmouse.com>wrote:

> To avoid a lot of ads, I use a trick where I identify the servers which
> are typically serving up ads, and remap them to 127.0.0.1 in my
> /etc/hosts file. This means I don't have to look at the ads. But it also
> means that I get a lot of apache barf on the page where the ad would be.
> The browser is trying to find whatever file is being asked for on my
> localhost, and apache can't find it (naturally). So there is 404 error
> text and the like.
>
> In order to avoid all this, is it possible to tell apache to server up a
> one-pixel graphic or somesuch whenever it's asked for a file I don't
> have? I don't actually serve any content from my localhost, even though
> apache is running in the background.
>
> Paul
>
> --
> Paul M. Foster
>

I believe you would have to use mod_rewrite to create a rewrite rule using
regexp. Unfortunately I don't really know regex all that well, but if all
fails here there's always #apache on irc.freenode.org

If you use an IP that isn't used or one in which a web server is not
running, instead of ads, you'll probably bog the browser down while it waits
for each ad to timeout. After a few moments you'll get 'the page cannot be
loaded' type messages so I think mod_rewrite is your best bet.

-- Clayton Holloway

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 15:02:57 EDT