From: Rich Bowen Prefix Substitution with
diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml
index 4e75300c1c..ce74347cb4 100644
--- a/docs/manual/mod/mod_rewrite.xml
+++ b/docs/manual/mod/mod_rewrite.xml
@@ -1387,6 +1387,14 @@ cannot use $N
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.
+ qsdiscard|QSD
'
+ (query string discard)redirect|R
[=code]' (force redirect)$N
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.qsdiscard|QSD
'
+ (query string discard)redirect|R
[=code]' (force redirect)
+When the requested URI contains a query string, and the target URI does
+not, the default behavior of RewriteRule
is to copy that query
+string to the target URI. Using the [QSD] flag causes the query string
+to be discarded.
+
+Using [QSD] and [QSA] together will result in [QSD] taking preference. +
+ +
+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 RewriteRule
target
+URI.
+
Use of the [R] flag causes a HTTP redirect to be issued to the browser. diff --git a/docs/manual/rewrite/flags.xml b/docs/manual/rewrite/flags.xml index cc20f8c21d..23a12e2180 100644 --- a/docs/manual/rewrite/flags.xml +++ b/docs/manual/rewrite/flags.xml @@ -377,6 +377,28 @@ will be discarded.
+
+When the requested URI contains a query string, and the target URI does
+not, the default behavior of
+Using [QSD] and [QSA] together will result in [QSD] taking preference. +
+ +
+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 RewriteRule
target
+URI.
+
Use of the [R] flag causes a HTTP redirect to be issued to the browser. diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 43e586625f..dd01c813ab 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -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