httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sorin Manolache" <sor...@gmail.com>
Subject Re: internal redirect
Date Sun, 14 Dec 2008 11:37:11 GMT
On Sun, Dec 14, 2008 at 06:20, Sam Carleton <scarleton@miltonstreet.com> wrote:
> On Sat, Dec 13, 2008 at 1:04 PM, Sorin Manolache <sorinm@gmail.com> wrote:
>
>> 3. Set a request note (apr_table_set(r->notes, "my_note",
>> "should_redirect")) and then in the handler hook you check the request
>> note. If it is set, ap_internal_redirect(your_url).
>
> This is what I want to do, make it 100% transparent to the client.  I
> put my hook handler at the first one and look for the note, if there I
> call ap_internal_redirect(), but my client is still getting a status
> code of 500.  The page I am trying to redirect to *IS* a PHP page,
> does that matter?

No, it doesn't.

> What format should the string in
> ap_internal_redirect() take, relative to the server or should the http
> and the server name be part of the string?  I want to redirect to:
>
> /invalidClient.html

ap_internal_redirect(r, "/invalidClient.html");

i.e. without protocol and server name.

I think the 500 was caused by an infinite loop:

When you perform an internal redirect, a new request_rec structure is
created and it is linked to the main request through the "prev" and
"next" fields. The newly created request will go through all (or most)
processing stages that its main request goes. Therefore, you risk here
to fall into infinite recursion:

1. access_status: sets a note in the main request
2. handler: checks the note, finds it, redirects the main request
3. access_status: sets a note in the redirected request
4. handler: checks the note, finds it, redirects the redirected request
5. etc.

Therefore, your handler must DECLINE redirects in order to avoid the
infinite loop:

if (!ap_is_initial_req(r))
  return DECLINED;
const char *note = apr_table_get(r->notes, "my_note");
if (note != 0 && strcmp(note, "should_redirect"))
  ap_internal_redirect(h, "/invalidClient.html");

Sorin


-- 
A: Because it reverses the logical flow of conversation.
Q: Why is top-posting frowned upon?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Mime
View raw message