23 static void *ngx_http_rewrite_create_loc_conf(
ngx_conf_t *cf);
24 static char *ngx_http_rewrite_merge_loc_conf(
ngx_conf_t *cf,
25 void *parent,
void *child);
34 static char * ngx_http_rewrite_if_condition(
ngx_conf_t *cf,
36 static char *ngx_http_rewrite_variable(
ngx_conf_t *cf,
40 static char * ngx_http_rewrite_value(
ngx_conf_t *cf,
57 ngx_http_rewrite_return,
65 ngx_http_rewrite_break,
107 ngx_http_rewrite_init,
115 ngx_http_rewrite_create_loc_conf,
116 ngx_http_rewrite_merge_loc_conf
122 &ngx_http_rewrite_module_ctx,
123 ngx_http_rewrite_commands,
157 if (rlcf->
codes == NULL) {
178 while (*(uintptr_t *) e->
ip) {
221 "using uninitialized \"%V\" variable", &var[data].
name);
230 ngx_http_rewrite_create_loc_conf(
ngx_conf_t *cf)
248 ngx_http_rewrite_merge_loc_conf(
ngx_conf_t *cf,
void *parent,
void *child)
260 if (conf->
codes == NULL) {
273 *code = (uintptr_t) NULL;
292 *h = ngx_http_rewrite_handler;
299 *h = ngx_http_rewrite_handler;
315 ngx_http_script_regex_code_t *regex;
316 ngx_http_script_regex_end_code_t *regex_end;
320 sizeof(ngx_http_script_regex_code_t));
325 ngx_memzero(regex,
sizeof(ngx_http_script_regex_code_t));
337 regex->regex = ngx_http_regex_compile(cf, &rc);
338 if (regex->regex == NULL) {
342 regex->code = ngx_http_script_regex_start_code;
344 regex->name = value[1];
346 if (value[2].data[value[2].len - 1] ==
'?') {
357 if (
ngx_strncmp(value[2].data,
"http://",
sizeof(
"http://") - 1) == 0
358 ||
ngx_strncmp(value[2].data,
"https://",
sizeof(
"https://") - 1) == 0
359 ||
ngx_strncmp(value[2].data,
"$scheme",
sizeof(
"$scheme") - 1) == 0)
370 }
else if (
ngx_strcmp(value[3].data,
"break") == 0) {
371 regex->break_cycle = 1;
374 }
else if (
ngx_strcmp(value[3].data,
"redirect") == 0) {
379 }
else if (
ngx_strcmp(value[3].data,
"permanent") == 0) {
386 "invalid parameter \"%V\"", &value[3]);
408 regex->size = sc.
size;
409 regex->args = sc.
args;
412 regex->lengths = NULL;
416 sizeof(ngx_http_script_regex_end_code_t),
418 if (regex_end == NULL) {
422 regex_end->code = ngx_http_script_regex_end_code;
423 regex_end->uri = regex->uri;
424 regex_end->args = regex->args;
425 regex_end->add_args = regex->add_args;
426 regex_end->redirect = regex->redirect;
473 && (
ngx_strncmp(p,
"http://",
sizeof(
"http://") - 1) == 0
474 ||
ngx_strncmp(p,
"https://",
sizeof(
"https://") - 1) == 0
475 ||
ngx_strncmp(p,
"$scheme",
sizeof(
"$scheme") - 1) == 0))
482 "invalid return code \"%V\"", &value[1]);
490 "invalid return code \"%V\"", &value[1]);
592 if (ngx_http_rewrite_if_condition(cf, lcf) !=
NGX_CONF_OK) {
597 if (if_code == NULL) {
635 ((u_char *) if_code + ((u_char *) lcf->
codes->
elts - elts));
639 - (u_char *) if_code;
659 ngx_http_script_regex_code_t *regex;
665 if (value[1].len < 1 || value[1].data[0] !=
'(') {
667 "invalid condition \"%V\"", &value[1]);
671 if (value[1].len == 1) {
680 if (value[last].len < 1 || value[last].data[value[last].len - 1] !=
')') {
682 "invalid condition \"%V\"", &value[last]);
686 if (value[last].len == 1) {
691 value[last].
data[value[last].
len] =
'\0';
694 len = value[cur].
len;
697 if (len > 1 && p[0] ==
'$') {
699 if (cur != last && cur + 2 != last) {
701 "invalid condition \"%V\"", &value[cur]);
705 if (ngx_http_rewrite_variable(cf, lcf, &value[cur]) !=
NGX_CONF_OK) {
715 len = value[cur].
len;
718 if (len == 1 && p[0] ==
'=') {
720 if (ngx_http_rewrite_value(cf, lcf, &value[last]) !=
NGX_CONF_OK) {
735 if (len == 2 && p[0] ==
'!' && p[1] ==
'=') {
737 if (ngx_http_rewrite_value(cf, lcf, &value[last]) !=
NGX_CONF_OK) {
751 if ((len == 1 && p[0] ==
'~')
752 || (len == 2 && p[0] ==
'~' && p[1] ==
'*')
753 || (len == 2 && p[0] ==
'!' && p[1] ==
'~')
754 || (len == 3 && p[0] ==
'!' && p[1] ==
'~' && p[2] ==
'*'))
757 sizeof(ngx_http_script_regex_code_t));
762 ngx_memzero(regex,
sizeof(ngx_http_script_regex_code_t));
771 regex->regex = ngx_http_regex_compile(cf, &rc);
772 if (regex->regex == NULL) {
776 regex->code = ngx_http_script_regex_start_code;
777 regex->next =
sizeof(ngx_http_script_regex_code_t);
780 regex->negative_test = 1;
782 regex->name = value[last];
788 "unexpected \"%V\" in condition", &value[cur]);
791 }
else if ((len == 2 && p[0] ==
'-')
792 || (len == 3 && p[0] ==
'!' && p[1] ==
'-'))
794 if (cur + 1 != last) {
796 "invalid condition \"%V\"", &value[cur]);
800 value[last].
data[value[last].
len] =
'\0';
803 if (ngx_http_rewrite_value(cf, lcf, &value[last]) !=
NGX_CONF_OK) {
858 "invalid condition \"%V\"", &value[cur]);
863 "invalid condition \"%V\"", &value[cur]);
881 if (index == NGX_ERROR) {
887 if (var_code == NULL) {
911 if (value[1].data[0] !=
'$') {
913 "invalid variable name \"%V\"", &value[1]);
926 if (index == NGX_ERROR) {
933 &&
ngx_strncasecmp(value[1].data, (u_char *)
"upstream_http_", 14) != 0)
939 if (ngx_http_rewrite_value(cf, lcf, &value[2]) !=
NGX_CONF_OK) {
946 if (vhcode == NULL) {
964 vcode->
index = (uintptr_t) index;
990 if (n == NGX_ERROR) {
995 val->
value = (uintptr_t) n;
1004 if (complex == NULL) {