From: Eric Covener Date: Sat, 4 Dec 2010 22:33:46 +0000 (+0000) Subject: PR 39313: allow the user to configure which rules come first when RewriteRules X-Git-Tag: 2.3.10~85 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=47280b545248f3899b532d7f6a273fe1122a213e;p=apache PR 39313: allow the user to configure which rules come first when RewriteRules are merged with RewriteOptions Inherit. Submitted By: Jérôme Grandjanny Reviewed By: covener git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1042255 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 88e017b58a..48fc211f26 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,10 @@ Changes with Apache 2.3.10 + *) mod_rewrite: Add 'RewriteOptions InheritBefore' to put the base + rules/conditions before the overridden rules/conditions. PR 39313. + [Jérôme Grandjanny ] + *) mod_autoindex: add IndexIgnoreReset to reset the list of IndexIgnored filenames in higher precedence configuration sections. PR 24243. [Eric Covener] diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml index 6afbf5571d..061beb53a0 100644 --- a/docs/manual/mod/mod_rewrite.xml +++ b/docs/manual/mod/mod_rewrite.xml @@ -140,7 +140,7 @@ later only be one of the following:

-
inherit
+
Inherit

This forces the current configuration to inherit the @@ -163,7 +163,16 @@ later after rules specified in the child scope.

+ +
InheritBefore
+
+

Like Inherit above, but the rules from the parent scope + are applied after rules specified in the child scope. + Available in Apache HTTP Server 2.3.10 and later.

+
+
+ diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 2f7a7dc9d4..431e5fa8d5 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -187,6 +187,7 @@ static const char* really_last_key = "rewrite_really_last"; #define OPTION_NONE 1<<0 #define OPTION_INHERIT 1<<1 +#define OPTION_INHERIT_BEFORE 1<<2 #ifndef RAND_MAX #define RAND_MAX 32767 @@ -2745,6 +2746,18 @@ static void *config_server_merge(apr_pool_t *p, void *basev, void *overridesv) a->rewriterules = apr_array_append(p, overrides->rewriterules, base->rewriterules); } + else if (a->options & OPTION_INHERIT_BEFORE) { + /* + * local directives override + * and anything else is inherited (preserving order) + */ + a->rewritemaps = apr_hash_overlay(p, base->rewritemaps, + overrides->rewritemaps); + a->rewriteconds = apr_array_append(p, base->rewriteconds, + overrides->rewriteconds); + a->rewriterules = apr_array_append(p, base->rewriterules, + overrides->rewriterules); + } else { /* * local directives override @@ -2810,6 +2823,12 @@ static void *config_perdir_merge(apr_pool_t *p, void *basev, void *overridesv) a->rewriterules = apr_array_append(p, overrides->rewriterules, base->rewriterules); } + else if (a->options & OPTION_INHERIT_BEFORE) { + a->rewriteconds = apr_array_append(p, base->rewriteconds, + overrides->rewriteconds); + a->rewriterules = apr_array_append(p, base->rewriterules, + overrides->rewriterules); + } else { a->rewriteconds = overrides->rewriteconds; a->rewriterules = overrides->rewriterules; @@ -2853,6 +2872,9 @@ static const char *cmd_rewriteoptions(cmd_parms *cmd, if (!strcasecmp(w, "inherit")) { options |= OPTION_INHERIT; } + else if (!strcasecmp(w, "inheritbefore")) { + options |= OPTION_INHERIT_BEFORE; + } else if (!strncasecmp(w, "MaxRedirects=", 13)) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, "RewriteOptions: MaxRedirects option has been "