From: Rich Bowen A mapping is maintained, from users to target servers, in
external map files. They look like: We put this into a to thus every URL path need not be valid on every backend physical
host. The following ruleset does this for us with the help of the map
files assuming that server0 is a default server which will be used if
a user has no entry in the map: Here a request for If you want one particular server to get more of the load than the
others, add it more times to the list. tags from
tags from
-user1 physical_host_of_user1
-user2 physical_host_of_user2
+
+user2 physical_host_of_user2
: :
-map.users-to-hosts file. The
aim is to map;
+
+
-RewriteEngine on
-
-RewriteMap users-to-hosts txt:/path/to/map.users-to-hosts
-
+
+
+RewriteMap users-to-hosts txt:/path/to/map.users-to-hosts
+
RewriteRule ^/u/([^/]+)/?(.*) http://${users-to-hosts:$1|server0}/u/$1/$2
-
-# This example is valid in per-directory context only
-RewriteCond %{REQUEST_FILENAME} !-s
+
+RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^page\.html$ page.cgi [T=application/x-httpd-cgi,L]
-page.html leads to an
internal run of a corresponding page.cgi if
@@ -164,20 +164,20 @@ RewriteRule ^page\.html$ page.cgi [
module="mod_rewrite">RewriteMap and a list of servers
to accomplish this.
-RewriteEngine on
-RewriteMap lb rnd:/path/to/serverlist.txt
-
+
+RewriteMap lb rnd:/path/to/serverlist.txt
+
RewriteRule ^/(.*) http://${lb:servers}/$1 [P,L]
-serverlist.txt will contain a list of the servers:
-## serverlist.txt
-
-servers one.example.com|two.example.com|three.example.com
-
+
+servers one.example.com|two.example.com|three.example.com
+
+RewriteRule ^(/[uge]/[^/]+/?.*):refresh /internal/cgi/apache/nph-refresh?f=$1 -
Now when we reference the URL
-+/u/foo/bar/page.html:refresh -
this leads to the internal invocation of the URL
-+/internal/cgi/apache/nph-refresh?f=/u/foo/bar/page.html -
The only missing part is the NPH-CGI script. Although one would usually say "left as an exercise to the reader" @@ -369,10 +369,10 @@ exit(0);
We use the following ruleset to expand the tilde URLs into the above layout.
--RewriteEngine on ++RewriteEngine on
RewriteRule ^/~(([a-z])[a-z0-9]+)(.*) /home/$2/$1/public_html$3 -
=STRING we can
do time-dependent redirects:
-
-RewriteEngine on
-RewriteCond %{TIME_HOUR}%{TIME_MIN} >0700
-RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900
-RewriteRule ^foo\.html$ foo.day.html [L]
+
+RewriteEngine on
+RewriteCond %{TIME_HOUR}%{TIME_MIN} >0700
+RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900
+RewriteRule ^foo\.html$ foo.day.html [L]
RewriteRule ^foo\.html$ foo.night.html
- This provides the content of foo.day.html
under the URL foo.html from
@@ -473,17 +473,17 @@ RewriteRule ^foo\.html$ foo.night.html
Use the [E] flag to set an environment variable.
--RewriteEngine on ++RewriteEngine on
RewriteRule ^/horse/(.*) /pony/$1 [E=rewritten:1] -
Later in your ruleset you might check for this environment variable using a RewriteCond:
-+RewriteCond %{ENV:rewritten} =1 -