Matt Hahnfeld wrote: > We need to rewrite redirects coming back from Apache2 mod_proxied sites > (specifically, change http urls to https urls). We already have > ProxyErrorOverride turned on for our proxied pages (and we need it for > other things), so we decided that using an "ErrorDocument 302" and a > little custom handler would work out best. Getting the "Location" out of > the original redirect is no problem -- we just use: > > $r->prev->headers_out->get('Location'); > > BUT, for the life of me I cannot figure out to rewrite the "Location:" > header to something different! For testing, I set up a little handler > that should rewrite every redirect to go to http://www.perl.org/. When I > use this as an ErrorDocument, it runs fine and I see the original > "Location" header print out properly to the error logs, but no new location > header is set (argh!). The existing Location header is sent through no > matter how many ways I try to reset it. > > So, how do I reset the "Location" header from an ErrorDocument 302 handler? > Any ideas?
I'm pretty sure you can't do what you're trying to do. basically, once you've entered the error document cycle I'm pretty sure the headers have already been sent and you're stuck. and trying to return other than OK from your /redirect location is what would ordinarily result in "also, a 302 error was encountered" in the stock error message (which you're overriding, so you don't see it). that said, I'm not sure I understand the reason you need to redirect twice - instead of using an ErrorDocument to redirect to a mod_perl handler that redirects to https, I might do something like this in a PerlInitHandler sub handler { ... if ($r->uri =~ m/thing I need to redirect/) { $r->custom_response(Apache2::Const::REDIRECT, $new_uri); return Apache2::Const::REDIRECT; } ... } or maybe I'm not following your route properly. but I'm pretty sure you can come up with a solution that doesn't involve two redirects, given access to the entire apache API :) --Geoff