From: Eric Covener
Date: Sat, 6 Dec 2014 14:13:44 +0000 (+0000)
Subject: Move some tweaked/re-tested recipes from https://wiki.apache.org/httpd/RewriteQuerySt...
X-Git-Tag: 2.5.0-alpha~3629
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a455db0e9db009f129830a4d9423b1fdac8453c4;p=apache
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/trunk@1643531 13f79535-47bb-0310-9956-ffa450edef68
---
diff --git a/docs/manual/rewrite/remapping.xml b/docs/manual/rewrite/remapping.xml
index 52427529ab..0cde299ff4 100644
--- a/docs/manual/rewrite/remapping.xml
+++ b/docs/manual/rewrite/remapping.xml
@@ -580,4 +580,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]
+
+
+
+
+
+
+
+
+
+