You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by co...@apache.org on 2010/12/04 23:33:46 UTC

svn commit: r1042255 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_rewrite.xml modules/mappers/mod_rewrite.c

Author: covener
Date: Sat Dec  4 22:33:46 2010
New Revision: 1042255

URL: http://svn.apache.org/viewvc?rev=1042255&view=rev
Log:
PR 39313: allow the user to configure which rules come first when RewriteRules
are merged with RewriteOptions Inherit.

Submitted By: Jérôme Grandjanny <jerome.grandjanny cea.fr> 
Reviewed By: covener

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml
    httpd/httpd/trunk/modules/mappers/mod_rewrite.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1042255&r1=1042254&r2=1042255&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Sat Dec  4 22:33:46 2010
@@ -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 <jerome.grandjanny cea.fr>]
+
   *) mod_autoindex: add IndexIgnoreReset to reset the list of IndexIgnored
      filenames in higher precedence configuration sections.  PR 24243.
      [Eric Covener]

Modified: httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml?rev=1042255&r1=1042254&r2=1042255&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml Sat Dec  4 22:33:46 2010
@@ -140,7 +140,7 @@ later</compatibility>
       only be one of the following:</p>
 
       <dl>
-      <dt><code>inherit</code></dt>
+      <dt><code>Inherit</code></dt>
       <dd>
       
       <p>This forces the current configuration to inherit the
@@ -163,7 +163,16 @@ later</compatibility>
       <strong>after</strong> rules specified in the child scope.
       </note>
       </dd>
+
+      <dt><code>InheritBefore</code></dt>
+      <dd>
+      <p> Like <code>Inherit</code> above, but the rules from the parent scope
+      are applied <strong>after</strong> rules specified in the child scope.  
+      Available in Apache HTTP Server 2.3.10 and later.</p>
+      </dd>
+      
       </dl>
+
 </usage>
 
 </directivesynopsis>

Modified: httpd/httpd/trunk/modules/mappers/mod_rewrite.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_rewrite.c?rev=1042255&r1=1042254&r2=1042255&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mappers/mod_rewrite.c (original)
+++ httpd/httpd/trunk/modules/mappers/mod_rewrite.c Sat Dec  4 22:33:46 2010
@@ -187,6 +187,7 @@ static const char* really_last_key = "re
 
 #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_poo
         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_poo
         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(cm
         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 "



Re: svn commit: r1042255 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_rewrite.xml modules/mappers/mod_rewrite.c

Posted by Eric Covener <co...@gmail.com>.
> This means that the local rules come after the global rules in the array.
> Doesn't this mean that they get applied after the global rules?

Yes, this is the right behavior and the opposite of the existing
Inherit option [that runs the parent rules after the local ones]

I think of it in these terms but understand that it might not be 100%
clear without consulting the manual:

  no option present: inherited rules do not run
  InheritBefore: inherited rules run before local rules
  Inherit[After]: inherited rules run after local rules (only option
before commit)

I'm afraid it would require a massive camel-case phrase in a directive
to make it clearer -- any short recommendations?

-- 
Eric Covener
covener@gmail.com

Re: svn commit: r1042255 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_rewrite.xml modules/mappers/mod_rewrite.c

Posted by Ruediger Pluem <rp...@apache.org>.

On 12/04/2010 11:33 PM, covener@apache.org wrote:
> Author: covener
> Date: Sat Dec  4 22:33:46 2010
> New Revision: 1042255
> 
> URL: http://svn.apache.org/viewvc?rev=1042255&view=rev
> Log:
> PR 39313: allow the user to configure which rules come first when RewriteRules
> are merged with RewriteOptions Inherit.
> 
> Submitted By: Jérôme Grandjanny <jerome.grandjanny cea.fr> 
> Reviewed By: covener
> 
> Modified:
>     httpd/httpd/trunk/CHANGES
>     httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml
>     httpd/httpd/trunk/modules/mappers/mod_rewrite.c
> 
> Modified: httpd/httpd/trunk/CHANGES

> Modified: httpd/httpd/trunk/modules/mappers/mod_rewrite.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_rewrite.c?rev=1042255&r1=1042254&r2=1042255&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/mappers/mod_rewrite.c (original)
> +++ httpd/httpd/trunk/modules/mappers/mod_rewrite.c Sat Dec  4 22:33:46 2010
> @@ -187,6 +187,7 @@ static const char* really_last_key = "re
>  
>  #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_poo
>          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);
> +    }

This means that the local rules come after the global rules in the array.
Doesn't this mean that they get applied after the global rules?

Regards

Rüdiger