John Zhang wrote:
I am using apache 2.0/2.2, in my output filter, I
would like to have the ability to redirect.  Some
tests indicated that I can redirect to a page on the
same site, but not to an external site.

Here is my code for redirect:
char* location = apr_table_get(r->headers_out, "Location");
//Note this Location is set by my filter during the
process, so I know I need to do a redirect.
if(location && location[0])
{
  //r->status = 301;
  r->method = apr_pstrdup(r->pool, "GET");
  r->method_number = M_GET;
  apr_table_unset(r->headers_in, "Content-Length");
  ap_remove_output_filter(my_filter);
  ap_internal_redirect_handler(location, r);
  return APR_SUCCESS;
}

//tests: (if my site is http://localhost/foo)
and when http://localhost/foo/bar.html (my test
page)is loaded I want to redirect it to
a) /foo/foo2/existing.html (works)
b) http://localhost/foo/foo2/existing.html (works)
c) http://www.google.com (does not work), instead I
get http://localhost/foo displayed on the browser.

Is there anything I did is incorrect?  I noticed the
method is called "*internal_redirect*", but did not
know another one for "external redirect".

An internal redirect should only work with internal redirects, and I do not know of an external.

I expect that you will have to set the f->r->status to 302, and maybe return a small page saying that the doc moved. Have you uncommented the r->status line and commented out the internal_redirect line? How did that work? (Note: an output filter, probably shouldn't be calling a handler. You may want to destroy the bucket brigade, and then create a new bucket brigade with the error message.)

Joe
--
Joseph Lewis <http://sharktooth.org/>

Reply via email to