From 609678cf32a94b21879f3797f9a79890235c59b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Malo?= Date: Mon, 29 Mar 2004 21:34:19 +0000 Subject: [PATCH] add support for rewrite rules in proxy containers PR: 27985 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@103199 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ modules/mappers/mod_rewrite.c | 31 ++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index b61e8dd902..a902bd875d 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) mod_rewrite now officially supports RewriteRules in sections. + PR 27985. [André Malo] + *) mod_cgid: Don't allow Scriptsock to be specified inside VirtualHost; Don't place script socket inside default server root instead of actual server root. PR 27886. [Jeff Trawick] diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 15976223c4..b7bd6b9bde 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -3590,12 +3590,19 @@ static int apply_rewrite_rule(rewriterule_entry *p, rewrite_ctx *ctx) int i, rc; char *newuri = NULL; request_rec *r = ctx->r; + int is_proxyreq = 0; ctx->uri = r->filename; if (ctx->perdir) { apr_size_t dirlen = strlen(ctx->perdir); + /* + * Proxy request? + */ + is_proxyreq = ( r->proxyreq && r->filename + && !strncmp(r->filename, "proxy:", 6)); + /* Since we want to match against the (so called) full URL, we have * to re-add the PATH_INFO postfix */ @@ -3608,7 +3615,7 @@ static int apply_rewrite_rule(rewriterule_entry *p, rewrite_ctx *ctx) /* Additionally we strip the physical path from the url to match * it independent from the underlaying filesystem. */ - if (strlen(ctx->uri) >= dirlen && + if (!is_proxyreq && strlen(ctx->uri) >= dirlen && !strncmp(ctx->uri, ctx->perdir, dirlen)) { rewritelog((r, 3, ctx->perdir, "strip per-dir prefix: %s -> %s", @@ -3721,7 +3728,8 @@ static int apply_rewrite_rule(rewriterule_entry *p, rewrite_ctx *ctx) * (1) it's an absolute URL path and * (2) it's a full qualified URL */ - if (ctx->perdir && *r->filename != '/' && !is_absolute_uri(r->filename)) { + if ( ctx->perdir && !is_proxyreq && *r->filename != '/' + && !is_absolute_uri(r->filename)) { rewritelog((r, 3, ctx->perdir, "add per-dir prefix: %s -> %s%s", r->filename, ctx->perdir, r->filename)); @@ -4338,6 +4346,7 @@ static int hook_fixup(request_rec *r) int rulestatus; int n; char *ofilename; + int is_proxyreq; dconf = (rewrite_perdir_conf *)ap_get_module_config(r->per_dir_config, &rewrite_module); @@ -4353,16 +4362,24 @@ static int hook_fixup(request_rec *r) return DECLINED; } + /* + * Proxy request? + */ + is_proxyreq = ( r->proxyreq && r->filename + && !strncmp(r->filename, "proxy:", 6)); + /* * .htaccess file is called before really entering the directory, i.e.: * URL: http://localhost/foo and .htaccess is located in foo directory * Ignore such attempts, since they may lead to undefined behaviour. */ - l = strlen(dconf->directory) - 1; - if (r->filename && strlen(r->filename) == l && - (dconf->directory)[l] == '/' && - !strncmp(r->filename, dconf->directory, l)) { - return DECLINED; + if (!is_proxyreq) { + l = strlen(dconf->directory) - 1; + if (r->filename && strlen(r->filename) == l && + (dconf->directory)[l] == '/' && + !strncmp(r->filename, dconf->directory, l)) { + return DECLINED; + } } /* -- 2.50.1