You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by co...@apache.org on 2014/12/06 15:13:44 UTC
svn commit: r1643531 - /httpd/httpd/trunk/docs/manual/rewrite/remapping.xml
Author: covener
Date: Sat Dec 6 14:13:44 2014
New Revision: 1643531
URL: http://svn.apache.org/r1643531
Log:
Move some tweaked/re-tested recipes from https://wiki.apache.org/httpd/RewriteQueryString into the
extended doc for mod_rewrite.
Modified:
httpd/httpd/trunk/docs/manual/rewrite/remapping.xml
Modified: httpd/httpd/trunk/docs/manual/rewrite/remapping.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/rewrite/remapping.xml?rev=1643531&r1=1643530&r2=1643531&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/rewrite/remapping.xml (original)
+++ httpd/httpd/trunk/docs/manual/rewrite/remapping.xml Sat Dec 6 14:13:44 2014
@@ -580,4 +580,66 @@ file, as well as in a <Directory>
</section>
+<section id="rewrite-query">
+<title>Rewrite query string</title>
+
+<dl>
+<dt>Description:</dt>
+<dd>You want to capture a particular value from a query string
+and either replace it or incorporate it into another component
+of the URL.</dd>
+
+<dt>Solutions:</dt>
+<dd>
+<p> 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.</p>
+<ul>
+ <li>This solution removes the matching key and value:
+
+<highlight language="config">
+# Remove mykey=???
+RewriteCond %{QUERY_STRING} (.*(?:^|&))mykey=([^&]*)&?(.*)&?$
+RewriteRule (.*) $1?%1%3
+</highlight>
+ </li>
+
+ <li>This solution uses the captured value in the URL subsitution,
+ discarding the rest of the original query by appending a '?':
+
+<highlight language="config">
+# Copy from query string to PATH_INFO
+RewriteCond %{QUERY_STRING} (.*(?:^|&))mykey=([^&]*)&?(.*)&?$
+RewriteRule (.*) $1/products/%2/? [PT]
+</highlight>
+ </li>
+
+ <li>This solution checks the captured value in a subsequent condition:
+
+<highlight language="config">
+# Capture the value of mykey in the query string
+RewriteCond %{QUERY_STRING} (.*(?:^|&))mykey=([^&]*)&?(.*)&?$
+RewriteCond %2 !=not-so-secret-value
+RewriteRule (.*) - [F]
+</highlight>
+ </li>
+
+ <li>This solution shows the reverse of the previous ones, copying
+ path components (perhaps PATH_INFO) from the URL into the query string.
+<highlight language="config">
+# The desired URL might be /products/kitchen-sink, and the script expects
+# /path?products=kitchen-sink.
+RewriteRule ^/?path/([^/]+)/([^/]+) /path?$1=$2 [PT]
+</highlight>
+ </li>
+</ul>
+
+</dd>
+
+</dl>
+</section>
+
+
</manualpage>