home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Complet / Apache / apache_2.0.52-win32-x86-no_ssl.msi / Data.Cab / F277759_urlmapping.xml < prev    next >
Extensible Markup Language  |  2004-04-17  |  14KB  |  297 lines

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
  3. <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
  4. <!-- $Revision: 1.3.2.8 $ -->
  5.  
  6. <!--
  7.  Copyright 2002-2004 The Apache Software Foundation
  8.  
  9.  Licensed under the Apache License, Version 2.0 (the "License");
  10.  you may not use this file except in compliance with the License.
  11.  You may obtain a copy of the License at
  12.  
  13.      http://www.apache.org/licenses/LICENSE-2.0
  14.  
  15.  Unless required by applicable law or agreed to in writing, software
  16.  distributed under the License is distributed on an "AS IS" BASIS,
  17.  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18.  See the License for the specific language governing permissions and
  19.  limitations under the License.
  20. -->
  21.  
  22. <manualpage metafile="urlmapping.xml.meta">
  23.  
  24.   <title>Mapping URLs to Filesystem Locations</title>
  25.  
  26.   <summary>
  27.     <p>This document explains how Apache uses the URL of a request
  28.     to determine the filesystem location from which to serve a
  29.     file.</p>
  30.   </summary>
  31.  
  32. <section id="related"><title>Related Modules and Directives</title>
  33.  
  34. <related>
  35. <modulelist>
  36. <module>mod_alias</module>
  37. <module>mod_proxy</module>
  38. <module>mod_rewrite</module>
  39. <module>mod_userdir</module>
  40. <module>mod_speling</module>
  41. <module>mod_vhost_alias</module>
  42. </modulelist>
  43. <directivelist>
  44. <directive module="mod_alias">Alias</directive>
  45. <directive module="mod_alias">AliasMatch</directive>
  46. <directive module="mod_speling">CheckSpelling</directive>
  47. <directive module="core">DocumentRoot</directive>
  48. <directive module="core">ErrorDocument</directive>
  49. <directive module="core">Options</directive>
  50. <directive module="mod_proxy">ProxyPass</directive>
  51. <directive module="mod_proxy">ProxyPassReverse</directive>
  52. <directive module="mod_alias">Redirect</directive>
  53. <directive module="mod_alias">RedirectMatch</directive>
  54. <directive module="mod_rewrite">RewriteCond</directive>
  55. <directive module="mod_rewrite">RewriteMatch</directive>
  56. <directive module="mod_alias">ScriptAlias</directive>
  57. <directive module="mod_alias">ScriptAliasMatch</directive>
  58. <directive module="mod_userdir">UserDir</directive>
  59. </directivelist>
  60. </related>
  61. </section>
  62.  
  63. <section id="documentroot"><title>DocumentRoot</title>
  64.  
  65.     <p>In deciding what file to serve for a given request, Apache's
  66.     default behavior is to take the URL-Path for the request (the part
  67.     of the URL following the hostname and port) and add it to the end
  68.     of the <directive module="core">DocumentRoot</directive> specified
  69.     in your configuration files. Therefore, the files and directories
  70.     underneath the <directive module="core">DocumentRoot</directive>
  71.     make up the basic document tree which will be visible from the
  72.     web.</p>
  73.  
  74.     <p>Apache is also capable of <a href="vhosts/">Virtual
  75.     Hosting</a>, where the server receives requests for more than one
  76.     host. In this case, a different <directive
  77.     module="core">DocumentRoot</directive> can be specified for each
  78.     virtual host, or alternatively, the directives provided by the
  79.     module <module>mod_vhost_alias</module> can
  80.     be used to dynamically determine the appropriate place from which
  81.     to serve content based on the requested IP address or
  82.     hostname.</p>
  83. </section>
  84.  
  85. <section id="outside"><title>Files Outside the DocumentRoot</title>
  86.  
  87.     <p>There are frequently circumstances where it is necessary to
  88.     allow web access to parts of the filesystem that are not strictly
  89.     underneath the <directive
  90.     module="core">DocumentRoot</directive>. Apache offers several
  91.     different ways to accomplish this. On Unix systems, symbolic links
  92.     can bring other parts of the filesystem under the <directive
  93.     module="core">DocumentRoot</directive>. For security reasons,
  94.     Apache will follow symbolic links only if the <directive
  95.     module="core">Options</directive> setting for the relevant
  96.     directory includes <code>FollowSymLinks</code> or
  97.     <code>SymLinksIfOwnerMatch</code>.</p>
  98.  
  99.     <p>Alternatively, the <directive
  100.     module="mod_alias">Alias</directive> directive will map any part
  101.     of the filesystem into the web space. For example, with</p>
  102.  
  103. <example>Alias /docs /var/web</example>
  104.  
  105.     <p>the URL <code>http://www.example.com/docs/dir/file.html</code>
  106.     will be served from <code>/var/web/dir/file.html</code>. The
  107.     <directive module="mod_alias">ScriptAlias</directive> directive
  108.     works the same way, with the additional effect that all content
  109.     located at the target path is treated as CGI scripts.</p>
  110.  
  111.     <p>For situations where you require additional flexibility, you
  112.     can use the <directive module="mod_alias">AliasMatch</directive> and 
  113.     <directive module="mod_alias">ScriptAliasMatch</directive>
  114.     directives to do powerful regular-expression based matching and
  115.     substitution. For example,</p>
  116.  
  117. <example>ScriptAliasMatch ^/~([a-zA-Z0-9]+)/cgi-bin/(.+)
  118.       /home/$1/cgi-bin/$2</example>
  119.  
  120.     <p>will map a request to
  121.     <code>http://example.com/~user/cgi-bin/script.cgi</code> to the
  122.     path <code>/home/user/cgi-bin/script.cgi</code> and will treat
  123.     the resulting file as a CGI script.</p>
  124. </section>
  125.  
  126. <section id="user"><title>User Directories</title>
  127.  
  128.     <p>Traditionally on Unix systems, the home directory of a
  129.     particular <em>user</em> can be referred to as
  130.     <code>~user/</code>. The module <module>mod_userdir</module>
  131.     extends this idea to the web by allowing files under each user's
  132.     home directory to be accessed using URLs such as the
  133.     following.</p>
  134.  
  135. <example>http://www.example.com/~user/file.html</example>
  136.  
  137.     <p>For security reasons, it is inappropriate to give direct
  138.     access to a user's home directory from the web. Therefore, the
  139.     <directive module="mod_userdir">UserDir</directive> directive
  140.     specifies a directory underneath the user's home directory
  141.     where web files are located. Using the default setting of
  142.     <code>Userdir public_html</code>, the above URL maps to a file
  143.     at a directory like
  144.     <code>/home/user/public_html/file.html</code> where
  145.     <code>/home/user/</code> is the user's home directory as
  146.     specified in <code>/etc/passwd</code>.</p>
  147.  
  148.     <p>There are also several other forms of the
  149.     <code>Userdir</code> directive which you can use on systems
  150.     where <code>/etc/passwd</code> does not contain the location of
  151.     the home directory.</p>
  152.  
  153.     <p>Some people find the "~" symbol (which is often encoded on the
  154.     web as <code>%7e</code>) to be awkward and prefer to use an
  155.     alternate string to represent user directories. This functionality
  156.     is not supported by mod_userdir. However, if users' home
  157.     directories are structured in a regular way, then it is possible
  158.     to use the <directive module="mod_alias">AliasMatch</directive>
  159.     directive to achieve the desired effect. For example, to make
  160.     <code>http://www.example.com/upages/user/file.html</code> map to
  161.     <code>/home/user/public_html/file.html</code>, use the following
  162.     <code>AliasMatch</code> directive:</p>
  163.  
  164. <example>AliasMatch ^/upages/([a-zA-Z0-9]+)/?(.*)
  165.       /home/$1/public_html/$2</example>
  166. </section>
  167.  
  168. <section id="redirect"><title>URL Redirection</title>
  169.  
  170.     <p>The configuration directives discussed in the above sections
  171.     tell Apache to get content from a specific place in the filesystem
  172.     and return it to the client. Sometimes, it is desirable instead to
  173.     inform the client that the requested content is located at a
  174.     different URL, and instruct the client to make a new request with
  175.     the new URL. This is called <em>redirection</em> and is
  176.     implemented by the <directive
  177.     module="mod_alias">Redirect</directive> directive. For example, if
  178.     the contents of the directory <code>/foo/</code> under the
  179.     <directive module="core">DocumentRoot</directive> are moved
  180.     to the new directory <code>/bar/</code>, you can instruct clients
  181.     to request the content at the new location as follows:</p>
  182.  
  183. <example>Redirect permanent /foo/
  184.       http://www.example.com/bar/</example>
  185.  
  186.     <p>This will redirect any URL-Path starting in
  187.     <code>/foo/</code> to the same URL path on the
  188.     <code>www.example.com</code> server with <code>/bar/</code>
  189.     substituted for <code>/foo/</code>. You can redirect clients to
  190.     any server, not only the origin server.</p>
  191.  
  192.     <p>Apache also provides a <directive
  193.     module="mod_alias">RedirectMatch</directive> directive for more
  194.     complicated rewriting problems. For example, to redirect requests
  195.     for the site home page to a different site, but leave all other
  196.     requests alone, use the following configuration:</p>
  197.  
  198. <example>RedirectMatch permanent ^/$
  199.       http://www.example.com/startpage.html</example>
  200.  
  201.     <p>Alternatively, to temporarily redirect all pages on one site
  202.     to a particular page on another site, use the following:</p>
  203.  
  204. <example>RedirectMatch temp .*
  205.       http://othersite.example.com/startpage.html</example>
  206. </section>
  207.  
  208. <section id="proxy"><title>Reverse Proxy</title>
  209.  
  210. <p>Apache also allows you to bring remote documents into the URL space
  211. of the local server.  This technique is called <em>reverse
  212. proxying</em> because the web server acts like a proxy server by
  213. fetching the documents from a remote server and returning them to the
  214. client.  It is different from normal proxying because, to the client,
  215. it appears the documents originate at the reverse proxy server.</p>
  216.  
  217. <p>In the following example, when clients request documents under the
  218. <code>/foo/</code> directory, the server fetches those documents from
  219. the <code>/bar/</code> directory on <code>internal.example.com</code>
  220. and returns them to the client as if they were from the local
  221. server.</p>
  222.  
  223. <example>
  224. ProxyPass /foo/ http://internal.example.com/bar/<br />
  225. ProxyPassReverse /foo/ http://internal.example.com/bar/
  226. </example>
  227.  
  228. <p>The <directive module="mod_proxy">ProxyPass</directive> configures
  229. the server to fetch the appropriate documents, while the
  230. <directive module="mod_proxy">ProxyPassReverse</directive>
  231. directive rewrites redirects originating at
  232. <code>internal.example.com</code> so that they target the appropriate
  233. directory on the local server.  It is important to note, however, that
  234. links inside the documents will not be rewritten.  So any absolute
  235. links on <code>internal.example.com</code> will result in the client
  236. breaking out of the proxy server and requesting directly from
  237. <code>internal.example.com</code>.</p>
  238. </section>
  239.  
  240. <section id="rewrite"><title>Rewriting Engine</title>
  241.  
  242.     <p>When even more powerful substitution is required, the rewriting
  243.     engine provided by <module>mod_rewrite</module>
  244.     can be useful. The directives provided by this module use
  245.     characteristics of the request such as browser type or source IP
  246.     address in deciding from where to serve content. In addition,
  247.     mod_rewrite can use external database files or programs to
  248.     determine how to handle a request. The rewriting engine is capable
  249.     of performing all three types of mappings discussed above:
  250.     internal redirects (aliases), external redirects, and proxying.
  251.     Many practical examples employing mod_rewrite are discussed in the
  252.     <a href="misc/rewriteguide.html">URL Rewriting Guide</a>.</p>
  253. </section>
  254.  
  255. <section id="notfound"><title>File Not Found</title>
  256.  
  257.     <p>Inevitably, URLs will be requested for which no matching
  258.     file can be found in the filesystem. This can happen for
  259.     several reasons. In some cases, it can be a result of moving
  260.     documents from one location to another. In this case, it is
  261.     best to use <a href="#redirect">URL redirection</a> to inform
  262.     clients of the new location of the resource. In this way, you
  263.     can assure that old bookmarks and links will continue to work,
  264.     even though the resource is at a new location.</p>
  265.  
  266.     <p>Another common cause of "File Not Found" errors is
  267.     accidental mistyping of URLs, either directly in the browser,
  268.     or in HTML links. Apache provides the module
  269.     <module>mod_speling</module> (sic) to help with
  270.     this problem. When this module is activated, it will intercept
  271.     "File Not Found" errors and look for a resource with a similar
  272.     filename. If one such file is found, mod_speling will send an
  273.     HTTP redirect to the client informing it of the correct
  274.     location. If several "close" files are found, a list of
  275.     available alternatives will be presented to the client.</p>
  276.  
  277.     <p>An especially useful feature of mod_speling, is that it will
  278.     compare filenames without respect to case. This can help
  279.     systems where users are unaware of the case-sensitive nature of
  280.     URLs and the unix filesystem. But using mod_speling for
  281.     anything more than the occasional URL correction can place
  282.     additional load on the server, since each "incorrect" request
  283.     is followed by a URL redirection and a new request from the
  284.     client.</p>
  285.  
  286.     <p>If all attempts to locate the content fail, Apache returns
  287.     an error page with HTTP status code 404 (file not found). The
  288.     appearance of this page is controlled with the
  289.     <directive module="core">ErrorDocument</directive> directive
  290.     and can be customized in a flexible manner as discussed in the
  291.     <a href="custom-error.html">Custom error responses</a> and <a
  292.     href="misc/custom_errordocs.html">International Server Error
  293.     Responses</a> documents.</p>
  294. </section>
  295.  
  296. </manualpage>
  297.