You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Allasso Travesser <al...@gmail.com> on 2013/12/11 18:01:55 UTC

[users@httpd] redirect within module?

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?

Thank you kindly,

Allasso
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] redirect within module?

Posted by Allasso Travesser <al...@gmail.com>.
Thanks Eric for suggesting mod_rewrite.

See findings below...

On Dec 11, 2013, at 10:26 AM, Eric Covener <co...@gmail.com> wrote:

> On Wed, Dec 11, 2013 at 12:01 PM, Allasso Travesser
> <al...@gmail.com> 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) {
    ap_internal_redirect("/path/newfile.html",r);
    return OK;
  }else{
    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) {
    ap_internal_redirect("/path/newfile.html",r);
    return OK;
  }else{
    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: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] redirect within module?

Posted by Ben Reser <be...@reser.org>.
On 12/11/13, 9:26 AM, Eric Covener wrote:
> 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.

I would stay away from duplicating what mod_rewrite does in translate_name for
internal redirects (aka PT or PassThrough).

See my email on the dev@ list with respect to mod_dav_svn and mod_rewrite for
an example of the problems here.  The current behavior of mod_rewrite assumes
that the core hook always updates the r->uri to the r->filename, but if some
other module needs to prevent the core hook from running and can be configured
per directory this creates a conflict between the two modules and you can use
one or the other but not both.  In the case of mod_rewrite and mod_dav_svn, it
means you can't use the PT flag to redirect out of a path that mod_dav_svn
thinks it is serving.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] redirect within module?

Posted by Eric Covener <co...@gmail.com>.
On Wed, Dec 11, 2013 at 12:01 PM, Allasso Travesser
<al...@gmail.com> 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.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org