Skip to content

Commit 8678d13

Browse files
committed
rewrite guide: redistribute advanced.xml recipes to topical files (BZ 58892, step 1)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1933612 13f79535-47bb-0310-9956-ffa450edef68
1 parent ebd74ed commit 8678d13

4 files changed

Lines changed: 315 additions & 63 deletions

File tree

docs/manual/rewrite/avoid.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,60 @@ and in certain other directives.</p>
243243

244244
</section>
245245

246+
<section id="load-balancing">
247+
248+
<title>Load Balancing</title>
249+
250+
<dl>
251+
<dt>Description:</dt>
252+
253+
<dd>
254+
<p>We wish to distribute load across several back-end
255+
servers.</p>
256+
</dd>
257+
258+
<dt>Solution:</dt>
259+
260+
<dd>
261+
<p>Use <module>mod_proxy_balancer</module>, which provides a
262+
flexible and featureful load-balancing solution. It supports
263+
several balancing algorithms, session stickiness, health checks,
264+
and dynamic configuration via the Balancer Manager — none of which
265+
are possible with a <module>mod_rewrite</module> approach.</p>
266+
267+
<highlight language="config">
268+
&lt;Proxy "balancer://mycluster"&gt;
269+
BalancerMember "http://one.example.com"
270+
BalancerMember "http://two.example.com"
271+
BalancerMember "http://three.example.com"
272+
&lt;/Proxy&gt;
273+
ProxyPass "/" "balancer://mycluster/"
274+
ProxyPassReverse "/" "balancer://mycluster/"
275+
</highlight>
276+
277+
</dd>
278+
279+
<dt>Discussion:</dt>
280+
<dd>
281+
282+
<p>It is possible to accomplish rudimentary random load balancing using
283+
<module>mod_rewrite</module> with a <code>rnd</code>
284+
<directive module="mod_rewrite">RewriteMap</directive>:</p>
285+
286+
<highlight language="config">
287+
RewriteEngine on
288+
RewriteMap lb "rnd:/path/to/serverlist.txt"
289+
RewriteRule "^/(.*)" "http://${lb:servers}/$1" [P,L]
290+
</highlight>
291+
292+
<p>However, <module>mod_proxy_balancer</module> is far more flexible and
293+
featureful than anything you can cobble together using
294+
<module>mod_rewrite</module>, and is the recommended approach.</p>
295+
296+
</dd>
297+
</dl>
298+
299+
</section>
300+
246301
</manualpage>
247302

docs/manual/rewrite/flags.xml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ characters rejected when they are copied into the query string unencoded.
153153
RewriteRule "^search/(.*)$" "/search.php/$1" "[BCTLS]"
154154
</highlight>
155155

156-
<p>This flag is available in version 2.4.57 and later.</p>
156+
<p>This flag is available in version 2.5.1 and later.</p>
157157

158158
</section>
159159

@@ -168,7 +168,7 @@ escaped.
168168
RewriteRule "^search/(.*)$" "/search.php?term=$1" "[B,BNE=/]"
169169
</highlight>
170170

171-
<p>This flag is available in version 2.4.57 and later.</p>
171+
<p>This flag is available in version 2.5.1 and later.</p>
172172
</section>
173173

174174
<section id="flag_c"><title>C|chain</title>
@@ -223,6 +223,7 @@ security model.</dd>
223223
<dd>A value of 0 indicates that the cookie will persist only for the
224224
current browser session. This is the default value if none is
225225
specified.</dd>
226+
<dd>A negative value causes the cookie to be unset in the browser.</dd>
226227

227228
<dt>Path</dt>
228229
<dd>The path, on the current website, for which the cookie is valid,
@@ -244,7 +245,7 @@ browsers that support this feature.</dd>
244245
<dt>samesite</dt>
245246
<dd>If set to anything other than <code>false</code> or <code>0</code>, the <code>SameSite</code>
246247
attribute is set to the specified value. Typical values are <code>None</code>,
247-
<code>Lax</code>, and <code>Strict</code>. Available in 2.4.47 and later.</dd>
248+
<code>Lax</code>, and <code>Strict</code>. Available in 2.5.1 and later.</dd>
248249
</dl>
249250

250251

@@ -346,6 +347,33 @@ CustomLog "logs/access_log" combined env=!image
346347
<p>Note that this same effect can be obtained using <directive
347348
module="mod_setenvif">SetEnvIf</directive>. This technique is offered as
348349
an example, not as a recommendation.</p>
350+
351+
<p><strong>Setting environment variables for tracking rewrites</strong></p>
352+
353+
<p>At times, we want to maintain some kind of status when we
354+
perform a rewrite. For example, you want to make a note that
355+
you've done that rewrite, so that you can check later to see if a
356+
request came via that rewrite. One way to do this is by setting an
357+
environment variable.</p>
358+
359+
<highlight language="config">
360+
RewriteEngine on
361+
RewriteRule "^/horse/(.*)" "/pony/$1" [E=<strong>rewritten:1</strong>]
362+
</highlight>
363+
364+
<p>Later in your ruleset you might check for this environment
365+
variable using a RewriteCond:</p>
366+
367+
<highlight language="config">
368+
RewriteCond "%{ENV:rewritten}" =1
369+
</highlight>
370+
371+
<p>Note that environment variables do not survive an external
372+
redirect. You might consider using the [CO] flag to set a
373+
cookie. For per-directory and htaccess rewrites, where the final
374+
substitution is processed as an internal redirect, environment
375+
variables from the previous round of rewriting are prefixed with
376+
"REDIRECT_". </p>
349377
</section>
350378

351379
<section id="flag_end"><title>END</title>
@@ -495,7 +523,7 @@ pattern still matches (i.e., while the URI still contains an
495523
<code>A</code>), perform this substitution (i.e., replace the
496524
<code>A</code> with a <code>B</code>).</p>
497525

498-
<p>In 2.4.8 and later, this module returns an error after 10,000 iterations to
526+
<p>In 2.5.0 and later, this module returns an error after 10,000 iterations to
499527
protect against unintended looping. An alternative maximum number of
500528
iterations can be specified by adding to the N flag. </p>
501529
<highlight language="config">
@@ -885,14 +913,14 @@ The <code>L</code> flag can be useful in this context to end the
885913
This protects from a malicious URL causing the expanded substitution to
886914
map to an unexpected filesystem location.</p>
887915

888-
<p><since>2.4.60</since></p>
916+
<p><since>2.5.1</since></p>
889917
</section>
890918
<section id="flag_unc"><title>UNC</title>
891919
<p> Setting this flag prevents the merging of multiple leading slashes,
892920
as used in Windows UNC paths. The flag is not necessary when the rules
893921
substitution starts with multiple literal slashes.</p>
894922

895-
<p><since>2.4.62</since></p>
923+
<p><since>2.5.1</since></p>
896924
</section>
897925

898926
</manualpage>

0 commit comments

Comments
 (0)