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.
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.
相关文章推荐
- December 21th Friday (十二月 二十一日 金曜日)
- December 28th Friday (十二月 二十八日 金曜日)
- 2008 November 14th Friday (十一月 十四日 金曜日)
- December 7th Friday (十二月 七日 金曜日)
- February 2nd Friday (一月 二日 金曜日)
- March 23th Friday (三月 二十三日 金曜日)
- Aprial 27th Friday (四月 二十七日 金曜日)
- August 10th Friday (八月 十日 金曜日)
- September 28th Friday (九月 二十八日 金曜日
- December 10th Monday (十二月 十日 月曜日)
- December 20th Thursday (十二月 二十日 木曜日)
- 2008 February 22th Friday (二月 二十二日 金曜日)
- 2008 April 25th Friday (四月 二十五日 金曜日)
- 2008 July 14th Monday (七月 十四日 月曜日)
- 2008 August 29th Friday (八月 二十九日 金曜日)
- 2008 October 10th Friday (十月 十日 金曜日)
- 2008 November 28th Friday (十一月 二十八日 金曜日)
- February 27th Friday 2009 (二月 二十七日 金曜日)
- April 17th Friday (四月 十七日 金曜日)
- June 12th Friday (六月 十二日 金曜日)