I tried to figure out how to configure Apache to return a 204 No Content using one of the built in modules, like mod_actions, mod_alias, or mod_headers.
Solution #1: Use RedirectMatch
As explained by Andrew Grangaard, you can use Apache's RedirectMatch directive to trigger on a specific URL pattern and reply with an HTTP 204 No Content response:
RedirectMatch 204 tracker(.*)$
This triggers on any URI starting with "tracker".
Solution #2: Use a Perl Script
You could also use Apache's SetHandler and Action directives to intercept the request and then call a Perl/CGI script to return a 204 No Content. In my kolich.com VirtualHost configuration, I used the Location directive to define the URI I wanted Apache to trigger on:
Action nocontent-handler /gen_204.cgi virtual
So this tells Apache to call gen_204.cgi each time a request comes starting with /tracker. For example, if you visit http://mark.koli.ch/tracker/heydude then your browser will get a HTTP 204 response back. Note the "virtual" modifier at the end of the Action directive. Defining the action as "virtual" is important because it tells Apache not to check if the requested file/resource actually exists. In the example above, /tracker/heydude doesn't actually exist (it's not a real resource on the server), so if you don't use the "virtual" modifier, Apache will return a 404 Not Found instead of calling the gen_204.cgi script.
Here's the gen_204.cgi Perl/CGI script I'm using that returns a 204 No Content. This is called by Apache anytime a request comes in starting with /tracker:
my $cgi = CGI->new();
print $cgi->header('text/html','204 No Content');
This seems to work very nicely.
Mark, why are you doing this?
FWIW, Google actually does something similar. Each time a user clicks on a link in their search results, Google pings itself to record the click; the response code from the ping is an HTTP 204. Here's a screenshot showing the Google ping.