Re: redirect within module?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks Eric for suggesting mod_rewrite.

See findings below...

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

> On Wed, Dec 11, 2013 at 12:01 PM, Allasso Travesser
> <allassopraise@xxxxxxxxx> 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@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx






[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux