I've been searching everywhere for a solution to do this, as well as trying many different things, and none of which so far work. Here's my problem. On an Apache server I need to process every html request under a certain directory/virtualhost/whatever and read a custom authentication cookie from another service. I need to decrypt and then read this auth cookie and then a.) redirect user to the login service (entirely different URL, not behind Apache), or b.) inject headers with basic information like username into the response and send the user to the document they requested.
I tried doing a CGI script where I would do a rewrite that would append the requested url as a query string to the cgi, which would execute the logic, and then redirect the user where necessary. But then I found out that the redirect will erase any headers I write. Next I tried using a cgi script with mod_ext_filter, which would be perfect but apparently you can't write headers with it, just the body (though someone please tell me I'm wrong about that, because it would be my solution). Finally I tried setting my cgi script as an action and adding it as a handler for .html paths but that just keeps giving me a "400 Bad Request" error (and doing Action verify_request test.rb makes apache run localhost/test.rb/{user}/index.html?). My last ditch effort might be to create a custom Apache module in C, but I'd really like to avoid this. (though if we're being really honest what I'd really like to do is write a custom REST API to handle this logic for our services)
So, what's the best way to implement this in Apache/should I even be putting this logic in Apache in the first place?