httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Allasso Travesser <>
Subject Re: [users@httpd] redirect within module?
Date Sun, 15 Dec 2013 03:36:03 GMT

Thanks Eric for suggesting mod_rewrite.

See findings below...

On Dec 11, 2013, at 10:26 AM, Eric Covener <> wrote:

> On Wed, Dec 11, 2013 at 12:01 PM, Allasso Travesser
> <> wrote:
>> Hello,
>> From within a module, I would like to redirect the user to a certain file on disk
if certain conditions are met.  Is there a straightforward way to do this, without doing something
like, apr_file_open -> ap_send_fd?
> If you can run in translate_name, just do what mod_alias does.
> If you have to run as a handler, maybe look at how mod_rewrite does
> its internal redirect.

In handler:

ap_internal_redirect(char* uri, request_rec r):

redirect one file to another:

  if (strcmp(r->uri,"/path/somefile.html") == 0) {
    return OK;
    return DECLINED;
conditional redirect - (test uri to make sure you don't redirect to same file and create loop):

  if (some_condition && strcmp(r->uri,"/path/newfile.html") != 0) {
    return OK;
    return DECLINED;

uri is path relative to site root.
Note that url in browser location bar will not change, so beware of caching issues.
I also observed that if setting cookies before the redirect, they may not get set when you
expect them to.

There is also ap_internal_redirect_handler, but I haven't explored the difference.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message