From: Rich Bowen Date: Fri, 14 Jan 2011 21:18:27 +0000 (+0000) Subject: Rebuild HTML. X-Git-Tag: 2.3.11~198 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acfa13d2e83ad18f972f7d6e090f2ff85d12794f;p=thirdparty%2Fapache%2Fhttpd.git Rebuild HTML. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1059175 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/advanced.html.en b/docs/manual/rewrite/advanced.html.en index 27055e76be4..a2dedf4d5b2 100644 --- a/docs/manual/rewrite/advanced.html.en +++ b/docs/manual/rewrite/advanced.html.en @@ -64,37 +64,37 @@ configuration.

A mapping is maintained, from users to target servers, in external map files. They look like:

-
-user1  physical_host_of_user1
-user2  physical_host_of_user2
+

+user1 physical_host_of_user1
+user2 physical_host_of_user2
: : -

+

We put this into a map.users-to-hosts file. The aim is to map;

-
+

/u/user1/anypath -

+

to

-
+

http://physical_host_of_user1/u/user/anypath -

+

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:

-
-RewriteEngine on
-
-RewriteMap      users-to-hosts   txt:/path/to/map.users-to-hosts
-
+

+RewriteEngine on
+
+RewriteMap users-to-hosts txt:/path/to/map.users-to-hosts
+
RewriteRule ^/u/([^/]+)/?(.*) http://${users-to-hosts:$1|server0}/u/$1/$2 -

+

@@ -120,11 +120,11 @@ RewriteRule ^/u/([^/]+)/?(.*) http://${users-to-hos
This is done via the following ruleset: -
-# This example is valid in per-directory context only
-RewriteCond %{REQUEST_FILENAME}   !-s
+

+# This example is valid in per-directory context only
+RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^page\.html$ page.cgi [T=application/x-httpd-cgi,L] -

+

Here a request for page.html leads to an internal run of a corresponding page.cgi if @@ -159,20 +159,20 @@ RewriteRule ^page\.html$ page.cgi [

We'll use RewriteMap and a list of servers to accomplish this.

-
-RewriteEngine on
-RewriteMap lb rnd:/path/to/serverlist.txt
-
+

+RewriteEngine on
+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
-
+

+## serverlist.txt
+
+servers one.example.com|two.example.com|three.example.com
+

If you want one particular server to get more of the load than the others, add it more times to the list.

@@ -213,21 +213,21 @@ featureful than anything you can cobble together using mod_rewrite.

URL causes the 'page' to be refreshed every time it is updated on the filesystem.

-
+

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" @@ -364,10 +364,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 -

+

@@ -423,13 +423,13 @@ RewriteRule ^/~(([a-z])[a-z0-9]+)(.*) /home/$2>STRING and =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 @@ -468,17 +468,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 -

+

diff --git a/docs/manual/rewrite/proxy.html.en b/docs/manual/rewrite/proxy.html.en index a98b3f2298b..f80e3327ce1 100644 --- a/docs/manual/rewrite/proxy.html.en +++ b/docs/manual/rewrite/proxy.html.en @@ -53,24 +53,24 @@ A number of recipes are provided that describe common scenarios.

To simply map a URL to another server, we use the [P] flag, as follows:

-
-RewriteEngine  on
-RewriteBase    /products/
-RewriteRule    ^widget/(.*)$  http://product.example.com/widget/$1  [P]
+

+RewriteEngine on
+RewriteBase /products/
+RewriteRule ^widget/(.*)$ http://product.example.com/widget/$1 [P]
ProxyPassReverse /products/widget/ http://product.example.com/widget/ -

+

In the second example, we proxy the request only if we can't find the resource locally. This can be very useful when you're migrating from one server to another, and you're not sure if all the content has been migrated yet.

-
-RewriteCond %{REQUEST_FILENAME}       !-f
-RewriteCond %{REQUEST_FILENAME}       !-d
-RewriteRule ^/(.*) http://old.example.com$1 [P]
+

+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule ^/(.*) http://old.example.com$1 [P]
ProxyPassReverse / http://old.example.com/ -

+

Discussion:
diff --git a/docs/manual/rewrite/remapping.html.en b/docs/manual/rewrite/remapping.html.en index fba46c2e604..97f7d1cb99a 100644 --- a/docs/manual/rewrite/remapping.html.en +++ b/docs/manual/rewrite/remapping.html.en @@ -71,10 +71,10 @@ configuration.

We rewrite the old URL to the new one internally via the following rule:

-
-RewriteEngine  on
+

+RewriteEngine on
RewriteRule ^/old\.html$ /new.html [PT] -

+

@@ -102,10 +102,10 @@ RewriteRule ^/old\.html$ /new.html [PT]

We force a HTTP redirect to the new URL which leads to a change of the browsers and thus the users view:

-
-RewriteEngine  on
+

+RewriteEngine on
RewriteRule ^/foo\.html$ bar.html [R] -

+

Discussion
@@ -144,18 +144,18 @@ RewriteRule ^/foo\.html$ bar.html [ -

With mod_rewrite

-RewriteEngine on
+

With mod_rewrite

+RewriteEngine on
RewriteRule ^/docs/(.+) http://new.example.com/docs/$1 [R,L] -

+

-

With RedirectMatch

+

With RedirectMatch

RedirectMatch ^/docs/(.*) http://new.example.com/docs/$1 -

+

-

With Redirect

+

With Redirect

Redirect /docs/ http://new.example.com/docs/ -

+

@@ -185,11 +185,11 @@ Redirect /docs/ http://new.example.com/docs/ internally leads to the invocation of /~quux/foo.cgi.

-
-RewriteEngine  on
-RewriteBase    /~quux/
+

+RewriteEngine on
+RewriteBase /~quux/
RewriteRule ^foo\.html$ foo.cgi [H=cgi-script] -

+

@@ -216,19 +216,21 @@ RewriteRule ^foo\.html$ foo.cgi [H= -
-#   backward compatibility ruleset for
-#   rewriting document.html to document.php
-#   when and only when document.php exists
-<Directory /var/www/htdocs>
-RewriteEngine on
-RewriteBase /var/www/htdocs
-
-RewriteCond $1.php -f
-RewriteCond $1.html !-f
-RewriteRule ^(.*).html$ $1.php
+

+# backward compatibility ruleset for
+# rewriting document.html to document.php
+# when and only when document.php exists
+<Directory /var/www/htdocs>
+ +RewriteEngine on
+RewriteBase /var/www/htdocs
+
+RewriteCond $1.php -f
+RewriteCond $1.html !-f
+RewriteRule ^(.*).html$ $1.php
+
</Directory> -

+

Discussion
@@ -320,19 +322,19 @@ Redirect /admin/ https://www.example.com/admin/ you might use one of the recipes below.

For sites running on a port other than 80:

-
-RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
-RewriteCond %{HTTP_HOST}   !^$
-RewriteCond %{SERVER_PORT} !^80$
+

+RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
+RewriteCond %{HTTP_HOST} !^$
+RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/?(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R,NE] -

+

And for a site running on port 80

-
-RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
-RewriteCond %{HTTP_HOST}   !^$
+

+RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
+RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE] -

+

If you wanted to do this generically for all domain names - that @@ -341,11 +343,11 @@ RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE] example.com, you could use the following recipe:

-
-RewriteCond %{HTTP_HOST} !^www\. [NC]
-RewriteCond %{HTTP_HOST} !^$
+

+RewriteCond %{HTTP_HOST} !^www\. [NC]
+RewriteCond %{HTTP_HOST} !^$
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.

@@ -375,23 +377,23 @@ RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R,NE] resource, and, if not finding it in either place, will attempt to just serve it out of the location requested.

-
-RewriteEngine on
-
-#   first try to find it in dir1/...
-#   ...and if found stop and be happy:
-RewriteCond         %{DOCUMENT_ROOT}/dir1/%{REQUEST_URI}  -f
-RewriteRule  ^(.+)  %{DOCUMENT_ROOT}/dir1/$1  [L]
-
-#   second try to find it in dir2/...
-#   ...and if found stop and be happy:
-RewriteCond         %{DOCUMENT_ROOT}/dir2/%{REQUEST_URI}  -f
-RewriteRule  ^(.+)  %{DOCUMENT_ROOT}/dir2/$1  [L]
-
-#   else go on for other Alias or ScriptAlias directives,
-#   etc.
+

+RewriteEngine on
+
+# first try to find it in dir1/...
+# ...and if found stop and be happy:
+RewriteCond %{DOCUMENT_ROOT}/dir1/%{REQUEST_URI} -f
+RewriteRule ^(.+) %{DOCUMENT_ROOT}/dir1/$1 [L]
+
+# second try to find it in dir2/...
+# ...and if found stop and be happy:
+RewriteCond %{DOCUMENT_ROOT}/dir2/%{REQUEST_URI} -f
+RewriteRule ^(.+) %{DOCUMENT_ROOT}/dir2/$1 [L]
+
+# else go on for other Alias or ScriptAlias directives,
+# etc.
RewriteRule ^ - [PT] -

+

@@ -419,22 +421,22 @@ RewriteRule ^ - [PT]

We'll use a RewriteMap directive to build a list of servers that we wish to use.

-
-HostnameLookups on
-RewriteEngine on
-RewriteMap    multiplex         txt:/path/to/map.mirrors
-RewriteCond  %{REMOTE_HOST}     ([a-z]+)$ [NC]
+

+HostnameLookups on
+RewriteEngine on
+RewriteMap multiplex txt:/path/to/map.mirrors
+RewriteCond %{REMOTE_HOST} ([a-z]+)$ [NC]
RewriteRule ^/(.*)$ ${multiplex:%1|http://www.example.com/}$1 [R,L] -

- -
-##  map.mirrors -- Multiplexing Map
+

-de http://www.example.de/ -uk http://www.example.uk/ -com http://www.example.com/ +

+## map.mirrors -- Multiplexing Map
+
+de http://www.example.de/
+uk http://www.example.uk/
+com http://www.example.com/
##EOF## -

+

Discussion
@@ -479,16 +481,16 @@ com http://www.example.com/ All other browsers receive page foo.32.html. This is done with the following ruleset:

-
-RewriteCond %{HTTP_USER_AGENT}  ^Mozilla/3.*
-RewriteRule ^foo\.html$         foo.NS.html          [L]
-
-RewriteCond %{HTTP_USER_AGENT}  ^Lynx/.*         [OR]
-RewriteCond %{HTTP_USER_AGENT}  ^Mozilla/[12].*
-RewriteRule ^foo\.html$         foo.20.html          [L]
-
+

+RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.*
+RewriteRule ^foo\.html$ foo.NS.html [L]
+
+RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR]
+RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].*
+RewriteRule ^foo\.html$ foo.20.html [L]
+
RewriteRule ^foo\.html$ foo.32.html [L] -

+

@@ -519,9 +521,9 @@ RewriteRule ^foo\.html$ foo.32.html [L we replace /puppies and /canines by the canonical /dogs.

-
+

RewriteRule ^/(puppies|canines)/(.*) /dogs/$2 [R] -

+

Discussion:
@@ -529,9 +531,9 @@ RewriteRule ^/(puppies|canines)/(.*) /dogs/$2 [R] This should really be accomplished with Redirect or RedirectMatch directives: -
+     

RedirectMatch ^/(puppies|canines)/(.*) /dogs/$2 -

+

@@ -560,10 +562,10 @@ using the following ruleset:

/about/:

-
-RewriteEngine on
+

+RewriteEngine on
RewriteRule ^/$ /about/ [R] -

+

Note that this can also be handled using the RedirectMatch directive:

@@ -597,32 +599,36 @@ that should go to an existing resource such as an image, or a css file.

As of version 2.2.16, you should use the FallbackResource directive for this:

-
-<Directory /var/www/my_blog>
-  FallbackResource index.php
+

+<Directory /var/www/my_blog>
+ + FallbackResource index.php
+
</Directory> -

+

However, in earlier versions of Apache, or if your needs are more complicated than this, you can use a variation of the following rewrite set to accomplish the same thing:

-
-<Directory /var/www/my_blog>
-  RewriteBase /my_blog
-
-  RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-f
-  RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-d
-  RewriteRule ^ index.php [PT]
+

+<Directory /var/www/my_blog>
+ + RewriteBase /my_blog
+
+ RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-f
+ RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-d
+ RewriteRule ^ index.php [PT]
+
</Directory> -

+

If, on the other hand, you wish to pass the requested URI as a query string argument to index.php, you can replace that RewriteRule with:

-
+

RewriteRule (.*) index.php?$1 [PT,QSA] -

+

Note that these rulesets can be uses in a .htaccess file, as well as in a <Directory> block.

diff --git a/docs/manual/rewrite/rewritemap.html.en b/docs/manual/rewrite/rewritemap.html.en index e35a7dc6a4a..febcf95c118 100644 --- a/docs/manual/rewrite/rewritemap.html.en +++ b/docs/manual/rewrite/rewritemap.html.en @@ -155,17 +155,17 @@ may be used, and give examples of each.

The file /etc/apache2/productmap.txt then contains the following:

-

Product to ID map

-##
-##  productmap.txt - Product to ID map file
-##
-
-television 993
-stereo     198
-fishingrod 043
-basketball 418
+    

Product to ID map

+##
+## productmap.txt - Product to ID map file
+##
+
+television 993
+stereo 198
+fishingrod 043
+basketball 418
telephone 328 -

+

Thus, when http://example.com/product/television is requested, the RewriteRule is applied, and the request @@ -207,14 +207,14 @@ telephone 328 to one of the servers in the 'static' pool, while everything else is sent to one of the 'dynamic' pool.

-

Rewrite map file

-##
-##  map.txt -- rewriting map
-##
-
-static   www1|www2|www3|www4
+    

Rewrite map file

+##
+## map.txt -- rewriting map
+##
+
+static www1|www2|www3|www4
dynamic www5|www6 -

+

Configuration directives

RewriteMap servers rnd:/path/to/file/map.txt