From 726ea1e1488bf63a5f82aaa7941de386bb43bead Mon Sep 17 00:00:00 2001
From: Eric Covener
Date: Sat, 6 Dec 2014 14:14:15 +0000
Subject: [PATCH] Merge r1643531 from trunk:
Move some tweaked/re-tested recipes from https://wiki.apache.org/httpd/RewriteQueryString into the
extended doc for mod_rewrite.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1643532 13f79535-47bb-0310-9956-ffa450edef68
---
docs/manual/rewrite/remapping.xml | 62 +++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/docs/manual/rewrite/remapping.xml b/docs/manual/rewrite/remapping.xml
index 335ad31a32..9ff7b29f7a 100644
--- a/docs/manual/rewrite/remapping.xml
+++ b/docs/manual/rewrite/remapping.xml
@@ -620,4 +620,66 @@ file, as well as in a <Directory> block.
+
+Rewrite query string
+
+
+- Description:
+- You want to capture a particular value from a query string
+and either replace it or incorporate it into another component
+of the URL.
+
+- Solutions:
+-
+
Many of the solutions in this section will all use the same condition,
+which leaves the matched value in the %2 backreference. %1 is the beginining
+of the query string (up to the key of intererest), and %3 is the remainder. This
+condition is a bit complex for flexibility and to avoid double '&&' in the
+substitutions.
+
+ - This solution removes the matching key and value:
+
+
+# Remove mykey=???
+RewriteCond %{QUERY_STRING} (.*(?:^|&))mykey=([^&]*)&?(.*)&?$
+RewriteRule (.*) $1?%1%3
+
+
+
+ - This solution uses the captured value in the URL subsitution,
+ discarding the rest of the original query by appending a '?':
+
+
+# Copy from query string to PATH_INFO
+RewriteCond %{QUERY_STRING} (.*(?:^|&))mykey=([^&]*)&?(.*)&?$
+RewriteRule (.*) $1/products/%2/? [PT]
+
+
+
+ - This solution checks the captured value in a subsequent condition:
+
+
+# Capture the value of mykey in the query string
+RewriteCond %{QUERY_STRING} (.*(?:^|&))mykey=([^&]*)&?(.*)&?$
+RewriteCond %2 !=not-so-secret-value
+RewriteRule (.*) - [F]
+
+
+
+ - This solution shows the reverse of the previous ones, copying
+ path components (perhaps PATH_INFO) from the URL into the query string.
+
+# The desired URL might be /products/kitchen-sink, and the script expects
+# /path?products=kitchen-sink.
+RewriteRule ^/?path/([^/]+)/([^/]+) /path?$1=$2 [PT]
+
+
+
+
+
+
+
+
+
+
--
2.40.0