* Apply a single RewriteRule */
| 4352 | * Apply a single RewriteRule |
| 4353 | */ |
| 4354 | static rule_return_type apply_rewrite_rule(rewriterule_entry *p, |
| 4355 | rewrite_ctx *ctx) |
| 4356 | { |
| 4357 | ap_regmatch_t regmatch[AP_MAX_REG_MATCH]; |
| 4358 | apr_array_header_t *rewriteconds; |
| 4359 | rewritecond_entry *conds; |
| 4360 | int i, rc; |
| 4361 | char *newuri = NULL; |
| 4362 | request_rec *r = ctx->r; |
| 4363 | int is_proxyreq = 0; |
| 4364 | int prefix_added = 0; |
| 4365 | |
| 4366 | ctx->uri = r->filename; |
| 4367 | |
| 4368 | if (ctx->perdir) { |
| 4369 | apr_size_t dirlen = strlen(ctx->perdir); |
| 4370 | |
| 4371 | /* |
| 4372 | * Proxy request? |
| 4373 | */ |
| 4374 | is_proxyreq = ( r->proxyreq && r->filename |
| 4375 | && !strncmp(r->filename, "proxy:", 6)); |
| 4376 | |
| 4377 | /* Since we want to match against the (so called) full URL, we have |
| 4378 | * to re-add the PATH_INFO postfix |
| 4379 | */ |
| 4380 | if (r->path_info && *r->path_info) { |
| 4381 | rewritelog(r, 3, ctx->perdir, "add path info postfix: %s -> %s%s", |
| 4382 | ctx->uri, ctx->uri, r->path_info); |
| 4383 | ctx->uri = apr_pstrcat(r->pool, ctx->uri, r->path_info, NULL); |
| 4384 | } |
| 4385 | |
| 4386 | /* Additionally we strip the physical path from the url to match |
| 4387 | * it independent from the underlying filesystem. |
| 4388 | */ |
| 4389 | if (!is_proxyreq && strlen(ctx->uri) >= dirlen && |
| 4390 | !strncmp(ctx->uri, ctx->perdir, dirlen)) { |
| 4391 | |
| 4392 | rewritelog(r, 3, ctx->perdir, "strip per-dir prefix: %s -> %s", |
| 4393 | ctx->uri, ctx->uri + dirlen); |
| 4394 | ctx->uri = ctx->uri + dirlen; |
| 4395 | } |
| 4396 | } |
| 4397 | |
| 4398 | /* Try to match the URI against the RewriteRule pattern |
| 4399 | * and exit immediately if it didn't apply. |
| 4400 | */ |
| 4401 | rewritelog(r, 3, ctx->perdir, "applying pattern '%s' to uri '%s'", |
| 4402 | p->pattern, ctx->uri); |
| 4403 | |
| 4404 | rc = !ap_regexec(p->regexp, ctx->uri, AP_MAX_REG_MATCH, regmatch, 0); |
| 4405 | if (! (( rc && !(p->flags & RULEFLAG_NOTMATCH)) || |
| 4406 | (!rc && (p->flags & RULEFLAG_NOTMATCH)) ) ) { |
| 4407 | return RULE_RC_NOMATCH; |
| 4408 | } |
| 4409 | |
| 4410 | /* It matched, wow! Now it's time to prepare the context structure for |
| 4411 | * further processing |
no test coverage detected