You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 1997/10/28 13:23:39 UTC

[PATCH] mod_rewrite redirects w/ QS in per-dir context

This patch fixes a problem in mod_rewrite (both Apache 1.2 and 1.3)
which Mark J Cox has reported to me these days:

     RewriteRule ^foo            /bar?query  [R]
     RewriteRule ^foo http://host/bar?query  [R]

In per-server context (httpd.conf) both worked fine, but in
per-directory context (.htaccess) only the first one worked
correct. The second one leaded to a

     Location: http://host/bar%3fquery

as the result (i.e. the `?' is escaped which is incorrect).  Below are two
patches (one for 1.3 and one for 1.2) which successfully (I've tested both
1.2.4 and 1.3b3 with this) fixed the problem. The fact is just that the second
explicit redirect case (subst part prefixed with http://) is handled different
in mod_rewrite and there the splitting out of the query args was missing.

Patch for Apache 1.3b3-dev:

Index: mod_rewrite.c
===================================================================
RCS file: /e/apache/REPOS/apachen/src/modules/standard/mod_rewrite.c,v
retrieving revision 1.54
diff -u -r1.54 mod_rewrite.c
--- mod_rewrite.c   1997/10/22 20:30:27 1.54
+++ mod_rewrite.c   1997/10/28 11:51:45
@@ -1706,7 +1706,11 @@
             }
             rewritelog(r, 2, "[per-dir %s] redirect %s -> %s", perdir,
                        r->filename, newuri);
+            /* set current URL... */
             r->filename = pstrdup(r->pool, newuri);
+            /* ...but split out the QUERY_STRING part */
+            splitout_queryargs(r, p->flags & RULEFLAG_QSAPPEND);
+            /* now stop processing with a forced redirect */
             r->status = p->forced_responsecode;
             return 1;
         }

Patch for Apache 1.2.5-dev:

Index: mod_rewrite.c
===================================================================
RCS file: /e/apache/REPOS/apache/src/mod_rewrite.c,v
retrieving revision 1.28.2.3
diff -u -r1.28.2.3 mod_rewrite.c
--- mod_rewrite.c   1997/08/17 20:35:49 1.28.2.3
+++ mod_rewrite.c   1997/10/28 11:53:52
@@ -1590,6 +1590,7 @@
             }
             rewritelog(r, 2, "[per-dir %s] redirect %s -> %s", perdir, r->filename, newuri);
             r->filename = pstrdup(r->pool, newuri);
+            splitout_queryargs(r, p->flags & RULEFLAG_QSAPPEND);
             r->status = p->forced_responsecode;
             return 1;
         }

Greetings,
                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com

Re: [PATCH] mod_rewrite redirects w/ QS in per-dir context

Posted by Mark J Cox <ma...@awe.com>.
> This patch fixes a problem in mod_rewrite (both Apache 1.2 and 1.3)
> which Mark J Cox has reported to me these days:

that patch fixes it, +1

Mark