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:14:40 UTC

svn commit: r1643533 - /httpd/httpd/trunk/docs/manual/rewrite/remapping.html.en

Author: covener
Date: Sat Dec  6 14:14:39 2014
New Revision: 1643533

URL: http://svn.apache.org/r1643533
Log:
xforms


Modified:
    httpd/httpd/trunk/docs/manual/rewrite/remapping.html.en

Modified: httpd/httpd/trunk/docs/manual/rewrite/remapping.html.en
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/rewrite/remapping.html.en?rev=1643533&r1=1643532&r2=1643533&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/rewrite/remapping.html.en (original)
+++ httpd/httpd/trunk/docs/manual/rewrite/remapping.html.en Sat Dec  6 14:14:39 2014
@@ -48,6 +48,7 @@ configuration.</div>
 <li><img alt="" src="../images/down.gif" /> <a href="#canonicalurl">Canonical URLs</a></li>
 <li><img alt="" src="../images/down.gif" /> <a href="#moveddocroot">Moved <code>DocumentRoot</code></a></li>
 <li><img alt="" src="../images/down.gif" /> <a href="#fallback-resource">Fallback Resource</a></li>
+<li><img alt="" src="../images/down.gif" /> <a href="#rewrite-query">Rewrite query string</a></li>
 </ul><h3>See also</h3><ul class="seealso"><li><a href="../mod/mod_rewrite.html">Module documentation</a></li><li><a href="intro.html">mod_rewrite introduction</a></li><li><a href="access.html">Controlling access</a></li><li><a href="vhosts.html">Virtual hosts</a></li><li><a href="proxy.html">Proxying</a></li><li><a href="rewritemap.html">Using RewriteMap</a></li><li><a href="advanced.html">Advanced techniques</a></li><li><a href="avoid.html">When not to use mod_rewrite</a></li></ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
 <div class="section">
@@ -565,6 +566,63 @@ file, as well as in a &lt;Directory&gt;
 
 </dl>
 
+</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
+<div class="section">
+<h2><a name="rewrite-query" id="rewrite-query">Rewrite query string</a></h2>
+
+
+<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 '&amp;&amp;' in the 
+substitutions.</p>
+<ul>
+  <li>This solution removes the matching key and value:
+
+<pre class="prettyprint lang-config"># Remove mykey=???
+RewriteCond %{QUERY_STRING} (.*(?:^|&amp;))mykey=([^&amp;]*)&amp;?(.*)&amp;?$
+RewriteRule (.*) $1?%1%3</pre>
+
+  </li>
+
+  <li>This solution uses the captured value in the URL subsitution,
+  discarding the rest of the original query by appending a '?':
+
+<pre class="prettyprint lang-config"># Copy from query string to PATH_INFO
+RewriteCond %{QUERY_STRING} (.*(?:^|&amp;))mykey=([^&amp;]*)&amp;?(.*)&amp;?$
+RewriteRule (.*) $1/products/%2/? [PT]</pre>
+
+  </li>
+
+  <li>This solution checks the captured value in a subsequent condition:
+
+<pre class="prettyprint lang-config"># Capture the value of mykey in the query string
+RewriteCond %{QUERY_STRING} (.*(?:^|&amp;))mykey=([^&amp;]*)&amp;?(.*)&amp;?$
+RewriteCond %2 !=not-so-secret-value 
+RewriteRule (.*) - [F]</pre>
+
+  </li>
+
+  <li>This solution shows the reverse of the previous ones, copying
+      path components (perhaps PATH_INFO) from the URL into the query string.
+<pre class="prettyprint lang-config"># The desired URL might be /products/kitchen-sink, and the script expects 
+# /path?products=kitchen-sink.
+RewriteRule ^/?path/([^/]+)/([^/]+) /path?$1=$2 [PT]</pre>
+
+  </li>
+</ul>
+
+</dd>
+
+</dl>
 </div></div>
 <div class="bottomlang">
 <p><span>Available Languages: </span><a href="../en/rewrite/remapping.html" title="English">&nbsp;en&nbsp;</a></p>