您的位置:首页 > 运维架构 > Apache

December 14th Friday (十二月 十四日 金曜日)

2008-01-07 20:33 405 查看
  Internal redirection can occur anywhere in the request processing cycle, provided that no data have been returned to the client as yet.

  Note that Apache's normal processing, including--where appropriate--functions implemented by your modules, will run within an internal
redirect.  Bear in mind that the configuration applied is that of the redirected URL, not the original URL.  Your handlers can determine
whether they are running in an internal redirect by r->prev field. Normally, its value will be NULL; in an internal rediexamining the
request_rec from before the redirection.  An internal redirection will also have an environment variable REDIRECT_STATUS set to the status
code of the original request at the time of redirection.

static int my_func(request_rec* r) {
  ...
  /* Are we in an internal redirect? */
  request_rec *original = r->prev ;
  if (original != NULL) {
    /* We're in an internal redirect from "original" */
  }
  else {
    /* It's a normal request */
  }
  ...
}

void ap_internal_redirect(const char *new_uri, request_rec *r)

  This is the canonical internal redirection function, and the mechanism to use if you have no strong reason to make another choice. This function
  creates a new request object for the new URL, and then runs the new request as if new_uri had been requested in the first place.

void ap_internal_fast_redirect(request_rec *new_req, request_rec *r)
  This function clones an existing request structure new_req into the running request r, so it can be used to set up a new request and simulate passing
  control to it.  This mechanism is sometimes used to promote a subrequest to a main request.

Subrequests

  A subrequest is a diversion to a new request. Unlike with internal redirection, however, processing returns to the original request after the subrequest
completes.

  Like the internal redirect and the error document, a subrequest will invoke functions from all modules hooked into the processing cycle, as appropriate.
Your functions can tell when they are invoked in a subrequest by looking at the r->main field of the request_rec;  its value is normally NULL, but in the
context of a subrequest it holds the parent request_rec.

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息