From: Rich Bowen Date: Sat, 2 May 2026 20:24:21 +0000 (+0000) Subject: rewrite guide: add Discussion sections to recipes where useful - alternatives, cross... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bd4ebbe66aa25b6d6ea95f5781d52fbbf81a6cc2;p=thirdparty%2Fapache%2Fhttpd.git rewrite guide: add Discussion sections to recipes where useful - alternatives, cross-references, caveats (BZ 58892, step 15) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1933728 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/remapping.xml b/docs/manual/rewrite/remapping.xml index 3322033d41..098a2a2353 100644 --- a/docs/manual/rewrite/remapping.xml +++ b/docs/manual/rewrite/remapping.xml @@ -68,7 +68,7 @@ RewriteEngine on RewriteRule "^/foo\.html$" "/bar.html" [PT] - + @@ -377,6 +377,15 @@ RedirectMatch "^/docs/(.*)" "http://new.example.com/docs/$1" Redirect "/docs/" "http://new.example.com/docs/" + +
Discussion:
+ +
+

For simple redirections to another server, the + Redirect or + RedirectMatch directives + are preferred, as they are simpler and more efficient.

+
@@ -530,6 +539,18 @@ RewriteRule "^/?(.*)" "http://www.%{HTTP_HOST}/$1" [L,R,NE]

These rulesets will work either in your main server configuration file, or in a .htaccess file placed in the DocumentRoot of the server.

+ +
Discussion:
+ +
+

If you have access to the server configuration, a + Redirect in a dedicated + VirtualHost + is the cleanest approach. Use the + If directive + as a middle ground, and mod_rewrite only if you + are limited to .htaccess.

+
@@ -574,6 +595,15 @@ RewriteRule "^(.+)" "%{DOCUMENT_ROOT}/dir2/$1" [L] RewriteRule "^" "-" [PT] + +
Discussion:
+ +
+

This is useful during migrations when content is being moved + between directories. For permanent setups, consider using + Alias or symbolic links + instead.

+
@@ -715,6 +745,15 @@ file, as well as in a <Directory> block.

+
Discussion:
+ +
+

The FallbackResource directive +is almost always the better choice for this use case. See the +When not to use mod_rewrite +document for a simpler one-line alternative.

+
+ @@ -777,6 +816,15 @@ RewriteRule "^/?path/([^/]+)/([^/]+)" "/path?$1=$2" [PT] +
Discussion:
+ +
+

See also the [QSA] and +[QSD] flags, which control whether +the original query string is appended to or discarded from the +substitution.

+
+ @@ -808,6 +856,15 @@ RewriteEngine on RewriteRule "^/~(([a-z])[a-z0-9]+)(.*)" "/home/$2/$1/public_html$3" + +
Discussion:
+ +
+

This technique is primarily useful for large hosting + environments with thousands of users. For most sites, + mod_userdir handles tilde-based user URLs + without requiring mod_rewrite.

+
@@ -883,6 +940,15 @@ RewriteRule "^foo\.html$" "foo.night.html" content dynamically, and customizing it based on the time of day. + +
Discussion:
+ +
+

Serving dynamic content through your application is almost + always a better approach. Caching by browsers, proxies, and + mod_cache makes time-based rewriting unreliable + in practice.

+
@@ -926,6 +992,16 @@ RewriteRule "^(.+)\.html$" "/regenerate_page.cgi" [PT,L] from the document directory, and they will then be regenerated the next time they are requested.

+ +
Discussion:
+ +
+

Modern approaches such as mod_cache, CDN + caching layers, or application-level caching provide more robust + and controllable solutions for serving pre-generated static + content. The -U subrequest test used here also + carries a performance cost on every request.

+
diff --git a/docs/manual/rewrite/rewritemap.xml b/docs/manual/rewrite/rewritemap.xml index 0f2221cb3c..2821e5547c 100644 --- a/docs/manual/rewrite/rewritemap.xml +++ b/docs/manual/rewrite/rewritemap.xml @@ -515,6 +515,16 @@ RewriteMap users-to-hosts "txt:/path/to/map.users-to-hosts" RewriteRule "^/u/([^/]+)/?(.*)" "http://${users-to-hosts:$1|server0}/u/$1/$2" + +
Discussion:
+ +
+

For distributing requests across backend servers, + mod_proxy_balancer provides a more robust and + configurable approach, with support for health checking, load + weighting, and session stickiness. The txt: map + approach shown here is simpler but lacks these features.

+

See the RewriteMap