* Apply a complete rule set, * i.e. a list of rewrite rules */
| 4634 | * i.e. a list of rewrite rules |
| 4635 | */ |
| 4636 | static int apply_rewrite_list(request_rec *r, apr_array_header_t *rewriterules, |
| 4637 | char *perdir, rewriterule_entry **lastsub) |
| 4638 | { |
| 4639 | rewriterule_entry *entries; |
| 4640 | rewriterule_entry *p; |
| 4641 | int i; |
| 4642 | int changed; |
| 4643 | rule_return_type rc; |
| 4644 | int s; |
| 4645 | rewrite_ctx *ctx; |
| 4646 | int round = 1; |
| 4647 | |
| 4648 | ctx = apr_palloc(r->pool, sizeof(*ctx)); |
| 4649 | ctx->perdir = perdir; |
| 4650 | ctx->r = r; |
| 4651 | *lastsub = NULL; |
| 4652 | |
| 4653 | /* |
| 4654 | * Iterate over all existing rules |
| 4655 | */ |
| 4656 | entries = (rewriterule_entry *)rewriterules->elts; |
| 4657 | changed = 0; |
| 4658 | loop: |
| 4659 | for (i = 0; i < rewriterules->nelts; i++) { |
| 4660 | p = &entries[i]; |
| 4661 | |
| 4662 | /* |
| 4663 | * Ignore this rule on subrequests if we are explicitly |
| 4664 | * asked to do so or this is a proxy-throughput or a |
| 4665 | * forced redirect rule. |
| 4666 | */ |
| 4667 | if (r->main != NULL && |
| 4668 | (p->flags & RULEFLAG_IGNOREONSUBREQ || |
| 4669 | p->flags & RULEFLAG_FORCEREDIRECT )) { |
| 4670 | continue; |
| 4671 | } |
| 4672 | |
| 4673 | /* |
| 4674 | * Apply the current rule. |
| 4675 | */ |
| 4676 | ctx->vary = NULL; |
| 4677 | rc = apply_rewrite_rule(p, ctx); |
| 4678 | |
| 4679 | if (rc != RULE_RC_NOMATCH) { |
| 4680 | |
| 4681 | if (!(p->flags & RULEFLAG_NOSUB)) { |
| 4682 | rewritelog(r, 2, perdir, "setting lastsub to rule with output %s", p->output); |
| 4683 | *lastsub = p; |
| 4684 | } |
| 4685 | |
| 4686 | /* Catch looping rules with pathinfo growing unbounded */ |
| 4687 | if ( strlen( r->filename ) > 2*r->server->limit_req_line ) { |
| 4688 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, |
| 4689 | "RewriteRule '%s' and URI '%s' " |
| 4690 | "exceeded maximum length (%d)", |
| 4691 | p->pattern, r->uri, 2*r->server->limit_req_line ); |
| 4692 | r->status = HTTP_INTERNAL_SERVER_ERROR; |
| 4693 | return ACTION_STATUS; |
no test coverage detected