I’ve got a virtual host in my Apache config to deal with ads, spam, and malware sites. It works by having bad servers redirect to a specific loopback address that is mapped to the virtual host via the HOSTS file.
Using the following directives, I have been able to replace any pages from bad servers with something like [ad] and any graphics from bad servers with a local 1x1, transparent PNG file.
RewriteRule \.(gif|jpg|png|jpeg)$ /1x1-trans.png
ErrorDocument 404 "<p>[ad]</p>"
However recently, I have seen pages with broken IMG tags because they use a SRC without a file extension.
<img src="http://badserver.com/adsandjunk/foobar;tile=4;sz=575x90;othervariables=stuff?">
I tried using
RewriteRule ^.*$ "<p>ad</p>" [L]
But that gives the broken image placeholders again. Using this
RewriteRule ^.*$ /1x1-trans.png [L]
Fixes the images, but then any non-images (like pages, frames, etc.) pop up a Save As dialog for the PNG.
How can I get Apache to replace graphics (ie any IMG tag) with a graphic and everything else with a bit of HTML?
Thanks a lot.