There are all kinds of methods for blocking banner ads.
However, I feel guilty about blocking ads from the smaller
sites that depend on the advertising income to stay afloat. I'm
getting the benefit of the site, but the sponsors don't
see any hits on their ads, so the site operator gets short-changed
by my filter.
I've used Perl to rectify this. I have set up Apache on my
local machine, and enabled mod_rewrite with a rule like this
in my httpd.conf:
RewriteEngine on
RewriteRule ^/.*$ /blank.cgi
Now, in /etc/hosts, I have a list of servers who only
serve ad content, similar to this:
127.0.0.1 adfu.blockstackers.com
127.0.0.1 ad.doubleclick.net
127.0.0.1 m.doubleclick.net
Now, when a request for any URL at one of the above servers
is made by my browser, it is diverted to my local http
server, and my custom CGI script. The CGI script makes a
connection to the ad server, figures out whether the content
is supposed to be text or an image, and then generates a
blank page or transparent gif for my browser to use in place of the ad.
It closes the connection before actually downloading the
ad.
The net result: I don't have to waste bandwidth on banner
ads, and the site operator still has a "GET" request for
the ad in their logs, so they still get paid (assuming they
get paid for page views instead of click-throughs)
I am posting the code as a reply to this message.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.