]> granicus.if.org Git - apache/commitdiff
Adds a [QSD] flag to RewriteRule to discard unwanted query strings
authorRich Bowen <rbowen@apache.org>
Tue, 29 Dec 2009 13:34:24 +0000 (13:34 +0000)
committerRich Bowen <rbowen@apache.org>
Tue, 29 Dec 2009 13:34:24 +0000 (13:34 +0000)
without the old kludge of sticking a ? on the end of the target URI.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@894383 13f79535-47bb-0310-9956-ffa450edef68

docs/manual/mod/mod_rewrite.html.en
docs/manual/mod/mod_rewrite.xml
docs/manual/rewrite/flags.html.en
docs/manual/rewrite/flags.xml
modules/mappers/mod_rewrite.c

index 1bf19c5cffcbe84dc271d160804e6a92abdeb47b..ab1f2600ca4f141737c5703758860d738a53ce3d 100644 (file)
@@ -1370,6 +1370,14 @@ cannot use <code>$N</code> in the substitution string!
         data to the query string via a rewrite rule. This rule has no net effect
         unless your substitution explicitly provides a new query string.</dd>
 
+        <dt>'<code>qsdiscard|QSD</code>'
+        (query string discard)</dt><dd>
+        Discards any query string attached to the incoming URI. Without
+        this flag, the query string will be automatically copied from
+        the request URI to the rewritten URL. Note, however, that if you
+        provide a query string on your target URI, that one will be used
+        instead.</dd>
+
         <dt>'<code>redirect|R</code>
           [=<em>code</em>]' (force <a id="redirect" name="redirect">redirect</a>)</dt><dd>
         <p>Prefix <em>Substitution</em> with
index 4e75300c1c828cc33fa32e0cd67e7a63792c5f18..ce74347cb4065f0cd10c920655e0e39fec826bf1 100644 (file)
@@ -1387,6 +1387,14 @@ cannot use <code>$N</code> in the substitution string!
         data to the query string via a rewrite rule. This rule has no net effect
         unless your substitution explicitly provides a new query string.</dd>
 
+        <dt>'<code>qsdiscard|QSD</code>'
+        (query string discard)</dt><dd>
+        Discards any query string attached to the incoming URI. Without
+        this flag, the query string will be automatically copied from
+        the request URI to the rewritten URL. Note, however, that if you
+        provide a query string on your target URI, that one will be used
+        instead.</dd>
+
         <dt>'<code>redirect|R</code>
           [=<em>code</em>]' (force <a id="redirect"
           name="redirect">redirect</a>)</dt><dd>
index 31c2089c8add925d836c32ae48ed499a6c45406d..811393f3647c3c597ab1efae10e244e2e782563f 100644 (file)
@@ -363,6 +363,27 @@ will be discarded.
 </p>
 
 
+<h3><a name="flag_qsd" id="flag_qsd">QSD|qsdiscard</a></h3>
+<p>
+When the requested URI contains a query string, and the target URI does
+not, the default behavior of <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> is to copy that query
+string to the target URI. Using the [QSD] flag causes the query string
+to be discarded.
+</p>
+
+<p>
+Using [QSD] and [QSA] together will result in [QSD] taking preference.
+</p>
+
+<p>
+If the target URI has a query string, the default behavior will be
+observed - that is, the original query string will be discarded and
+replaced with the query string in the <code>RewriteRule</code> target
+URI.
+</p>
+
+
+
 <h3><a name="flag_r" id="flag_r">R|redirect</a></h3>
 <p>
 Use of the [R] flag causes a HTTP redirect to be issued to the browser.
index cc20f8c21d3762578fa34c3e55c7527f0d88559d..23a12e218021daeac430060d1a39b918529fbfdd 100644 (file)
@@ -377,6 +377,28 @@ will be discarded.
 </p>
 </section>
 
+<section id="flag_qsd"><title>QSD|qsdiscard</title>
+<p>
+When the requested URI contains a query string, and the target URI does
+not, the default behavior of <directive
+module="mod_rewrite">RewriteRule</directive> is to copy that query
+string to the target URI. Using the [QSD] flag causes the query string
+to be discarded.
+</p>
+
+<p>
+Using [QSD] and [QSA] together will result in [QSD] taking preference.
+</p>
+
+<p>
+If the target URI has a query string, the default behavior will be
+observed - that is, the original query string will be discarded and
+replaced with the query string in the <code>RewriteRule</code> target
+URI.
+</p>
+
+</section>
+
 <section id="flag_r"><title>R|redirect</title>
 <p>
 Use of the [R] flag causes a HTTP redirect to be issued to the browser.
index 43e586625fa857ef1c5b2d7ebfaf86189ee8e3f6..dd01c813aba4c54096c1bfdc7f1eac8f31320d1b 100644 (file)
@@ -153,6 +153,7 @@ static void (*dbd_prepare)(server_rec*, const char*, const char*) = NULL;
 #define RULEFLAG_STATUS             1<<13
 #define RULEFLAG_ESCAPEBACKREF      1<<14
 #define RULEFLAG_DISCARDPATHINFO    1<<15
+#define RULEFLAG_QSDISCARD          1<<16
 
 /* return code of the rewrite rule
  * the result may be escaped - or not
@@ -754,7 +755,7 @@ static char *escape_absolute_uri(apr_pool_t *p, char *uri, unsigned scheme)
  * split out a QUERY_STRING part from
  * the current URI string
  */
-static void splitout_queryargs(request_rec *r, int qsappend)
+static void splitout_queryargs(request_rec *r, int qsappend, int qsdiscard)
 {
     char *q;
 
@@ -770,6 +771,11 @@ static void splitout_queryargs(request_rec *r, int qsappend)
         return;
     }
 
+    if ( qsdiscard ) {
+        r->args = NULL; /* Discard query string */
+        rewritelog((r, 2, NULL, "discarding query string"));
+    }
+
     q = ap_strchr(r->filename, '?');
     if (q != NULL) {
         char *olduri;
@@ -3493,6 +3499,9 @@ static const char *cmd_rewriterule_setflag(apr_pool_t *p, void *_cfg,
         if (   !strcasecmp(key, "SA")
             || !strcasecmp(key, "sappend")) {              /* qsappend */
             cfg->flags |= RULEFLAG_QSAPPEND;
+        } else if ( !strcasecmp(key, "SD")
+                || !strcasecmp(key, "sdiscard") ) {       /* qsdiscard */
+            cfg->flags |= RULEFLAG_QSDISCARD;
         }
         else {
             ++error;
@@ -3998,7 +4007,7 @@ static int apply_rewrite_rule(rewriterule_entry *p, rewrite_ctx *ctx)
         r->path_info = NULL; 
     }
 
-    splitout_queryargs(r, p->flags & RULEFLAG_QSAPPEND);
+    splitout_queryargs(r, p->flags & RULEFLAG_QSAPPEND, p->flags & RULEFLAG_QSDISCARD);
 
     /* Add the previously stripped per-directory location prefix, unless
      * (1) it's an absolute URL path and