Tim (infamous_tim) wrote in apache,
Tim
infamous_tim
apache

  • Mood:

Redirect _all_ queries to a single file

So I got tired of seeing advertisements on every web page I visit, really really tired. I downloaded a hosts file (http://someonewhocares.org/hosts/) that declares a huge list of servers known to display ads as 127.0.0.1, which redirects it to the copy of apache I run continuously. This of course speeds up page loads quite a bit, but it would display "page not found" errors everywhere an ad used to be. Sometimes it would just have a picture frame, but the picture would be empty. In any case, I was happy that the ads were gone.
Then I got to thinking (uh oh!), how could I make this better? I wanted to remove the page not found text and replace it with a blank nothing, like a transparent gif or something. As it turns out, usually the requests the ad servers are to subdirectories or whatnot, usually long strings of meaningless characters. There's no possible way to put a transparent gif at every possible location, but I can use mod_rewrite instead.
I tried playing around a bit, and came up with the idea of redirecting all requests to a small 1x1 gif that was a single transparent pixel. Problem is, I can't seem to get it to do what I want. Here is the simple rule I came up with in .htaccess

options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteRule (.*) /trans.gif


I have .htaccess and trans.gif stored in the root of my webserver's directory, which is /Library/WebServer/Documents. I adjusted the entry for that directory to be "AllowOverride All" just in case. Now the server is returning "Internal Server Error" instead of page not found. What am I doing wrong?

Thanks in advance!
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 7 comments