From: Rich Bowen Date: Mon, 2 Nov 2009 23:49:53 +0000 (+0000) Subject: Moves more recipes to their new locations, with some minor changes to X-Git-Tag: 2.3.3~78 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7cd7a2b84617213e97bc6d72ee52ab8e8f57d4e;p=apache Moves more recipes to their new locations, with some minor changes to each. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@832204 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/remapping.html.en b/docs/manual/rewrite/remapping.html.en index c95321f17f..4da1dd33b3 100644 --- a/docs/manual/rewrite/remapping.html.en +++ b/docs/manual/rewrite/remapping.html.en @@ -28,14 +28,177 @@ how you can use mod_rewri request. This includes many examples of common uses of mod_rewrite, including detailed descriptions of how each works.

-

Note that many of these examples won't work unchanged in your +

Note that many of these examples won't work unchanged in your particular server configuration, so it's important that you understand them, rather than merely cutting and pasting the examples into your -configuration.

+configuration.
-
- + +
top
+
+

From Old to New (internal)

+ + + +
+
Description:
+ +
+

Assume we have recently renamed the page + foo.html to bar.html and now want + to provide the old URL for backward compatibility. However, + we want that users of the old URL even not recognize that + the pages was renamed - that is, we don't want the address to + change in their browser.

+
+ +
Solution:
+ +
+

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

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

Rewriting From Old to New (external)

+ + + +
+
Description:
+ +
+

Assume again that we have recently renamed the page + foo.html to bar.html and now want + to provide the old URL for backward compatibility. But this + time we want that the users of the old URL get hinted to + the new one, i.e. their browsers Location field should + change, too.

+
+ +
Solution:
+ +
+

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

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

In this example, as contrasted to the internal example above, we can simply + use the Redirect directive. mod_rewrite was used in that earlier + example in order to hide the redirect from the client:

+ +

+ Redirect /foo.html /bar.html +

+ +
+
+ +
top
+
+

From Static to Dynamic

+ + + +
+
Description:
+ +
+

How can we transform a static page + foo.html into a dynamic variant + foo.cgi in a seamless way, i.e. without notice + by the browser/user.

+
+ +
Solution:
+ +
+

We just rewrite the URL to the CGI-script and force the + handler to be cgi-script so that it is + executed as a CGI program. + This way a request to /~quux/foo.html + internally leads to the invocation of + /~quux/foo.cgi.

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

Canonical Hostnames

+ +
+
Description:
+ +
The goal of this rule is to force the use of a particular + hostname, in preference to other hostnames which may be used to + reach the same site. For example, if you wish to force the use + of www.example.com instead of + example.com, you might use a variant of the + following recipe.
+ +
Solution:
+ +
+

For sites running on a port other than 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}   !^$
+RewriteRule ^/?(.*)         http://www.example.com/$1 [L,R,NE]
+
+ +

+ If you wanted to do this generically for all domain names - that + is, if you want to redirect example.com to + www.example.com for all possible values of + example.com, you could use the following + recipe:

+ +
+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.

+
+
+ +

Available Languages:  en 

  • Canonical URLs
  • -
  • Canonical Hostnames
  • Moved DocumentRoot
  • Trailing Slash Problem
  • Move Homedirs to Different Webserver
  • @@ -53,9 +52,6 @@
  • Redirecting Anchors
  • Time-Dependent Rewriting
  • Backward Compatibility for YYYY to XXXX migration
  • -
  • From Old to New (intern)
  • -
  • From Old to New (extern)
  • -
  • From Static to Dynamic
  • Proxy Deny
  • External Rewriting Engine
  • Web Cluster with Consistent URL Space
  • @@ -117,56 +113,6 @@ RewriteRule ^/u/([^/]+)$ /$1/$2/ [
    top
    -

    Canonical Hostnames

    - -
    -
    Description:
    - -
    The goal of this rule is to force the use of a particular - hostname, in preference to other hostnames which may be used to - reach the same site. For example, if you wish to force the use - of www.example.com instead of - example.com, you might use a variant of the - following recipe.
    - -
    Solution:
    - -
    -

    For sites running on a port other than 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}   !^$
    -RewriteRule ^/?(.*)         http://www.example.com/$1 [L,R,NE]
    -
    - -

    - If you wanted to do this generically for all domain names - that - is, if you want to redirect example.com to - www.example.com for all possible values of - example.com, you could use the following - recipe:

    - -
    -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.

    -
    -
    - -
    top
    -

    Moved DocumentRoot

    @@ -554,103 +500,6 @@ RewriteRule ^(.*)$ $1.html
    top
    -

    From Old to New (intern)

    - - - -
    -
    Description:
    - -
    -

    Assume we have recently renamed the page - foo.html to bar.html and now want - to provide the old URL for backward compatibility. Actually - we want that users of the old URL even not recognize that - the pages was renamed.

    -
    - -
    Solution:
    - -
    -

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

    - -
    -RewriteEngine  on
    -RewriteBase    /~quux/
    -RewriteRule    ^foo\.html$  bar.html
    -
    -
    -
    - -
    top
    -
    -

    From Old to New (extern)

    - - - -
    -
    Description:
    - -
    -

    Assume again that we have recently renamed the page - foo.html to bar.html and now want - to provide the old URL for backward compatibility. But this - time we want that the users of the old URL get hinted to - the new one, i.e. their browsers Location field should - change, too.

    -
    - -
    Solution:
    - -
    -

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

    - -
    -RewriteEngine  on
    -RewriteBase    /~quux/
    -RewriteRule    ^foo\.html$  bar.html  [R]
    -
    -
    -
    - -
    top
    -
    -

    From Static to Dynamic

    - - - -
    -
    Description:
    - -
    -

    How can we transform a static page - foo.html into a dynamic variant - foo.cgi in a seamless way, i.e. without notice - by the browser/user.

    -
    - -
    Solution:
    - -
    -

    We just rewrite the URL to the CGI-script and force the - handler to be cgi-script so that it is - executed as a CGI program. - This way a request to /~quux/foo.html - internally leads to the invocation of - /~quux/foo.cgi.

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

    Proxy Deny

    diff --git a/docs/manual/rewrite/rewrite_guide.xml b/docs/manual/rewrite/rewrite_guide.xml index 5b62850312..10e664803b 100644 --- a/docs/manual/rewrite/rewrite_guide.xml +++ b/docs/manual/rewrite/rewrite_guide.xml @@ -89,57 +89,6 @@ RewriteRule ^/u/([^/]+)$ /$1/$2/ [ -
    Canonical Hostnames - -
    -
    Description:
    - -
    The goal of this rule is to force the use of a particular - hostname, in preference to other hostnames which may be used to - reach the same site. For example, if you wish to force the use - of www.example.com instead of - example.com, you might use a variant of the - following recipe.
    - -
    Solution:
    - -
    -

    For sites running on a port other than 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}   !^$
    -RewriteRule ^/?(.*)         http://www.example.com/$1 [L,R,NE]
    -
    - -

    - If you wanted to do this generically for all domain names - that - is, if you want to redirect example.com to - www.example.com for all possible values of - example.com, you could use the following - recipe:

    - -
    -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.

    -
    -
    - -
    -
    Moved <code>DocumentRoot</code> @@ -530,103 +479,6 @@ RewriteRule ^(.*)$ $1.html
    -
    - - From Old to New (intern) - -
    -
    Description:
    - -
    -

    Assume we have recently renamed the page - foo.html to bar.html and now want - to provide the old URL for backward compatibility. Actually - we want that users of the old URL even not recognize that - the pages was renamed.

    -
    - -
    Solution:
    - -
    -

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

    - -
    -RewriteEngine  on
    -RewriteBase    /~quux/
    -RewriteRule    ^foo\.html$  bar.html
    -
    -
    -
    - -
    - -
    - - From Old to New (extern) - -
    -
    Description:
    - -
    -

    Assume again that we have recently renamed the page - foo.html to bar.html and now want - to provide the old URL for backward compatibility. But this - time we want that the users of the old URL get hinted to - the new one, i.e. their browsers Location field should - change, too.

    -
    - -
    Solution:
    - -
    -

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

    - -
    -RewriteEngine  on
    -RewriteBase    /~quux/
    -RewriteRule    ^foo\.html$  bar.html  [R]
    -
    -
    -
    - -
    - -
    - - From Static to Dynamic - -
    -
    Description:
    - -
    -

    How can we transform a static page - foo.html into a dynamic variant - foo.cgi in a seamless way, i.e. without notice - by the browser/user.

    -
    - -
    Solution:
    - -
    -

    We just rewrite the URL to the CGI-script and force the - handler to be cgi-script so that it is - executed as a CGI program. - This way a request to /~quux/foo.html - internally leads to the invocation of - /~quux/foo.cgi.

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