home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / apache_2.2.8-win32-x86-no_ssl.msi / Data1.cab / _88CC74C04FAFA87B6D6D512E669982B3 < prev    next >
Extensible Markup Language  |  2007-09-01  |  22KB  |  385 lines

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
  4.         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  5.               This file is generated from xml source: DO NOT EDIT
  6.         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  7.       -->
  8. <title>Apache Tutorial: .htaccess files - Apache HTTP Server</title>
  9. <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
  10. <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
  11. <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
  12. <link href="../images/favicon.ico" rel="shortcut icon" /></head>
  13. <body id="manual-page"><div id="page-header">
  14. <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
  15. <p class="apache">Apache HTTP Server Version 2.2</p>
  16. <img alt="" src="../images/feather.gif" /></div>
  17. <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
  18. <div id="path">
  19. <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.2</a> > <a href="./">How-To / Tutorials</a></div><div id="page-content"><div id="preamble"><h1>Apache Tutorial: .htaccess files</h1>
  20. <div class="toplang">
  21. <p><span>Available Languages: </span><a href="../en/howto/htaccess.html" title="English"> en </a> |
  22. <a href="../ja/howto/htaccess.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
  23. <a href="../ko/howto/htaccess.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
  24. <a href="../pt-br/howto/htaccess.html" hreflang="pt-br" rel="alternate" title="PortuguΩs (Brasil)"> pt-br </a></p>
  25. </div>
  26.  
  27. <p><code>.htaccess</code> files provide a way to make configuration
  28. changes on a per-directory basis.</p>
  29. </div>
  30. <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#related">.htaccess files</a></li>
  31. <li><img alt="" src="../images/down.gif" /> <a href="#what">What they are/How to use them</a></li>
  32. <li><img alt="" src="../images/down.gif" /> <a href="#when">When (not) to use .htaccess files</a></li>
  33. <li><img alt="" src="../images/down.gif" /> <a href="#how">How directives are applied</a></li>
  34. <li><img alt="" src="../images/down.gif" /> <a href="#auth">Authentication example</a></li>
  35. <li><img alt="" src="../images/down.gif" /> <a href="#ssi">Server Side Includes example</a></li>
  36. <li><img alt="" src="../images/down.gif" /> <a href="#cgi">CGI example</a></li>
  37. <li><img alt="" src="../images/down.gif" /> <a href="#troubleshoot">Troubleshooting</a></li>
  38. </ul></div>
  39. <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  40. <div class="section">
  41. <h2><a name="related" id="related">.htaccess files</a></h2>
  42.     <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="../mod/core.html">core</a></code></li><li><code class="module"><a href="../mod/mod_authn_file.html">mod_authn_file</a></code></li><li><code class="module"><a href="../mod/mod_authz_groupfile.html">mod_authz_groupfile</a></code></li><li><code class="module"><a href="../mod/mod_cgi.html">mod_cgi</a></code></li><li><code class="module"><a href="../mod/mod_include.html">mod_include</a></code></li><li><code class="module"><a href="../mod/mod_mime.html">mod_mime</a></code></li></ul></td><td><ul><li><code class="directive"><a href="../mod/core.html#accessfilename">AccessFileName</a></code></li><li><code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code></li><li><code class="directive"><a href="../mod/core.html#options">Options</a></code></li><li><code class="directive"><a href="../mod/mod_mime.html#addhandler">AddHandler</a></code></li><li><code class="directive"><a href="../mod/core.html#sethandler">SetHandler</a></code></li><li><code class="directive"><a href="../mod/core.html#authtype">AuthType</a></code></li><li><code class="directive"><a href="../mod/core.html#authname">AuthName</a></code></li><li><code class="directive"><a href="../mod/mod_authn_file.html#authuserfile">AuthUserFile</a></code></li><li><code class="directive"><a href="../mod/mod_authz_groupfile.html#authgroupfile">AuthGroupFile</a></code></li><li><code class="directive"><a href="../mod/core.html#require">Require</a></code></li></ul></td></tr></table>
  43. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  44. <div class="section">
  45. <h2><a name="what" id="what">What they are/How to use them</a></h2>
  46.  
  47.  
  48.     <p><code>.htaccess</code> files (or "distributed configuration files")
  49.     provide a way to make configuration changes on a per-directory basis. A
  50.     file, containing one or more configuration directives, is placed in a
  51.     particular document directory, and the directives apply to that
  52.     directory, and all subdirectories thereof.</p>
  53.  
  54.     <div class="note"><h3>Note:</h3>
  55.       <p>If you want to call your <code>.htaccess</code> file something
  56.       else, you can change the name of the file using the <code class="directive"><a href="../mod/core.html#accessfilename">AccessFileName</a></code> directive. For example,
  57.       if you would rather call the file <code>.config</code> then you
  58.       can put the following in your server configuration file:</p>
  59.  
  60.       <div class="example"><p><code>
  61.         AccessFileName .config
  62.       </code></p></div>
  63.     </div>
  64.  
  65.     <p>In general, <code>.htaccess</code> files use the same syntax as
  66.     the <a href="../configuring.html#syntax">main configuration
  67.     files</a>.  What you can put in these files is determined by the
  68.     <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code> directive. This
  69.     directive specifies, in categories, what directives will be
  70.     honored if they are found in a <code>.htaccess</code> file. If a
  71.     directive is permitted in a <code>.htaccess</code> file, the
  72.     documentation for that directive will contain an Override section,
  73.     specifying what value must be in <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code> in order for that
  74.     directive to be permitted.</p>
  75.  
  76.     <p>For example, if you look at the documentation for the <code class="directive"><a href="../mod/core.html#adddefaultcharset">AddDefaultCharset</a></code>
  77.     directive, you will find that it is permitted in <code>.htaccess</code>
  78.     files. (See the Context line in the directive summary.) The <a href="../mod/directive-dict.html#Context">Override</a> line reads
  79.     <code>FileInfo</code>. Thus, you must have at least
  80.     <code>AllowOverride FileInfo</code> in order for this directive to be
  81.     honored in <code>.htaccess</code> files.</p>
  82.  
  83.     <div class="example"><h3>Example:</h3><table>
  84.         <tr>
  85.           <td><a href="../mod/directive-dict.html#Context">Context:</a></td>
  86.           <td>server config, virtual host, directory, .htaccess</td>
  87.         </tr>
  88.  
  89.         <tr>
  90.           <td><a href="../mod/directive-dict.html#Override">Override:</a></td>
  91.           <td>FileInfo</td>
  92.         </tr>
  93.       </table></div>
  94.  
  95.     <p>If you are unsure whether a particular directive is permitted in a
  96.     <code>.htaccess</code> file, look at the documentation for that
  97.     directive, and check the Context line for ".htaccess".</p>
  98.     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  99. <div class="section">
  100. <h2><a name="when" id="when">When (not) to use .htaccess files</a></h2>
  101.  
  102.     <p>In general, you should never use <code>.htaccess</code> files unless
  103.     you don't have access to the main server configuration file. There is,
  104.     for example, a prevailing misconception that user authentication should
  105.     always be done in <code>.htaccess</code> files. This is simply not the
  106.     case. You can put user authentication configurations in the main server
  107.     configuration, and this is, in fact, the preferred way to do
  108.     things.</p>
  109.  
  110.     <p><code>.htaccess</code> files should be used in a case where the
  111.     content providers need to make configuration changes to the server on a
  112.     per-directory basis, but do not have root access on the server system.
  113.     In the event that the server administrator is not willing to make
  114.     frequent configuration changes, it might be desirable to permit
  115.     individual users to make these changes in <code>.htaccess</code> files
  116.     for themselves. This is particularly true, for example, in cases where
  117.     ISPs are hosting multiple user sites on a single machine, and want
  118.     their users to be able to alter their configuration.</p>
  119.  
  120.     <p>However, in general, use of <code>.htaccess</code> files should be
  121.     avoided when possible. Any configuration that you would consider
  122.     putting in a <code>.htaccess</code> file, can just as effectively be
  123.     made in a <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code> section in your main server 
  124.     configuration file.</p>
  125.  
  126.     <p>There are two main reasons to avoid the use of
  127.     <code>.htaccess</code> files.</p>
  128.  
  129.     <p>The first of these is performance. When <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code>
  130.     is set to allow the use of <code>.htaccess</code> files, Apache will
  131.     look in every directory for <code>.htaccess</code> files. Thus,
  132.     permitting <code>.htaccess</code> files causes a performance hit,
  133.     whether or not you actually even use them! Also, the
  134.     <code>.htaccess</code> file is loaded every time a document is
  135.     requested.</p>
  136.  
  137.     <p>Further note that Apache must look for <code>.htaccess</code> files
  138.     in all higher-level directories, in order to have a full complement of
  139.     directives that it must apply. (See section on <a href="#how">how
  140.     directives are applied</a>.) Thus, if a file is requested out of a
  141.     directory <code>/www/htdocs/example</code>, Apache must look for the
  142.     following files:</p>
  143.  
  144.     <div class="example"><p><code>
  145.       /.htaccess<br />
  146.       /www/.htaccess<br />
  147.       /www/htdocs/.htaccess<br />
  148.       /www/htdocs/example/.htaccess
  149.     </code></p></div>
  150.  
  151.     <p>And so, for each file access out of that directory, there are 4
  152.     additional file-system accesses, even if none of those files are
  153.     present. (Note that this would only be the case if
  154.     <code>.htaccess</code> files were enabled for <code>/</code>, which
  155.     is not usually the case.)</p>
  156.  
  157.     <p>The second consideration is one of security. You are permitting
  158.     users to modify server configuration, which may result in changes over
  159.     which you have no control. Carefully consider whether you want to give
  160.     your users this privilege. Note also that giving users less
  161.     privileges than they need will lead to additional technical support
  162.     requests. Make sure you clearly tell your users what level of
  163.     privileges you have given them. Specifying exactly what you have set
  164.     <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code> to, and pointing them
  165.     to the relevant documentation, will save yourself a lot of confusion
  166.     later.</p>
  167.  
  168.     <p>Note that it is completely equivalent to put a <code>.htaccess</code>
  169.     file in a directory <code>/www/htdocs/example</code> containing a
  170.     directive, and to put that same directive in a Directory section
  171.     <code><Directory /www/htdocs/example></code> in your main server
  172.     configuration:</p>
  173.  
  174.     <p><code>.htaccess</code> file in <code>/www/htdocs/example</code>:</p>
  175.  
  176.     <div class="example"><h3>Contents of .htaccess file in
  177.     <code>/www/htdocs/example</code></h3><p><code>
  178.         AddType text/example .exm
  179.     </code></p></div>
  180.  
  181.     <div class="example"><h3>Section from your <code>httpd.conf</code>
  182.     file</h3><p><code>
  183.       <Directory /www/htdocs/example><br />
  184.       <span class="indent">
  185.         AddType text/example .exm<br />
  186.       </span>
  187.       </Directory>
  188.     </code></p></div>
  189.  
  190.     <p>However, putting this configuration in your server configuration
  191.     file will result in less of a performance hit, as the configuration is
  192.     loaded once when Apache starts, rather than every time a file is
  193.     requested.</p>
  194.  
  195.     <p>The use of <code>.htaccess</code> files can be disabled completely
  196.     by setting the <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code>
  197.     directive to <code>none</code>:</p>
  198.  
  199.     <div class="example"><p><code>
  200.       AllowOverride None
  201.     </code></p></div>
  202. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  203. <div class="section">
  204. <h2><a name="how" id="how">How directives are applied</a></h2>
  205.  
  206.     <p>The configuration directives found in a <code>.htaccess</code> file
  207.     are applied to the directory in which the <code>.htaccess</code> file
  208.     is found, and to all subdirectories thereof. However, it is important
  209.     to also remember that there may have been <code>.htaccess</code> files
  210.     in directories higher up. Directives are applied in the order that they
  211.     are found. Therefore, a <code>.htaccess</code> file in a particular
  212.     directory may override directives found in <code>.htaccess</code> files
  213.     found higher up in the directory tree. And those, in turn, may have
  214.     overridden directives found yet higher up, or in the main server
  215.     configuration file itself.</p>
  216.  
  217.     <p>Example:</p>
  218.  
  219.     <p>In the directory <code>/www/htdocs/example1</code> we have a
  220.     <code>.htaccess</code> file containing the following:</p>
  221.  
  222.     <div class="example"><p><code>
  223.        Options +ExecCGI
  224.     </code></p></div>
  225.  
  226.     <p>(Note: you must have "<code>AllowOverride Options</code>" in effect
  227.     to permit the use of the "<code class="directive"><a href="../mod/core.html#options">Options</a></code>" directive in
  228.     <code>.htaccess</code> files.)</p>
  229.  
  230.     <p>In the directory <code>/www/htdocs/example1/example2</code> we have
  231.     a <code>.htaccess</code> file containing:</p>
  232.  
  233.     <div class="example"><p><code>
  234.        Options Includes
  235.     </code></p></div>
  236.  
  237.     <p>Because of this second <code>.htaccess</code> file, in the directory
  238.     <code>/www/htdocs/example1/example2</code>, CGI execution is not
  239.     permitted, as only <code>Options Includes</code> is in effect, which
  240.     completely overrides any earlier setting that may have been in
  241.     place.</p>
  242.  
  243.     <h3><a name="merge" id="merge">Merging of .htaccess with the main
  244.     configuration files</a></h3>
  245.  
  246.     <p>As discussed in the documentation on <a href="../sections.html">Configuration Sections</a>,
  247.     <code>.htaccess</code> files can override the <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code> sections for
  248.     the corresponding directory, but will be overriden by other types
  249.     of configuration sections from the main configuration files.  This
  250.     fact can be used to enforce certain configurations, even in the
  251.     presence of a liberal <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code> setting.  For example, to
  252.     prevent script execution while allowing anything else to be set in
  253.     <code>.htaccess</code> you can use:</p>
  254.  
  255.     <div class="example"><p><code>
  256. <Directory /><br />
  257. <span class="indent">
  258. Allowoverride All<br />
  259. </span>
  260. </Directory><br />
  261. <br />
  262. <Location /><br />
  263. <span class="indent">
  264. Options +IncludesNoExec -ExecCGI<br />
  265. </span>
  266. </Location>
  267.     </code></p></div>
  268.  
  269.  
  270. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  271. <div class="section">
  272. <h2><a name="auth" id="auth">Authentication example</a></h2>
  273.  
  274.     <p>If you jumped directly to this part of the document to find out how
  275.     to do authentication, it is important to note one thing. There is a
  276.     common misconception that you are required to use
  277.     <code>.htaccess</code> files in order to implement password
  278.     authentication. This is not the case. Putting authentication directives
  279.     in a <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code>
  280.     section, in your main server configuration file, is the preferred way
  281.     to implement this, and <code>.htaccess</code> files should be used only
  282.     if you don't have access to the main server configuration file. See <a href="#when">above</a> for a discussion of when you should and should
  283.     not use <code>.htaccess</code> files.</p>
  284.  
  285.     <p>Having said that, if you still think you need to use a
  286.     <code>.htaccess</code> file, you may find that a configuration such as
  287.     what follows may work for you.</p>
  288.  
  289.     <p><code>.htaccess</code> file contents:</p>
  290.  
  291.     <div class="example"><p><code>
  292.       AuthType Basic<br />
  293.       AuthName "Password Required"<br />
  294.       AuthUserFile /www/passwords/password.file<br />
  295.       AuthGroupFile /www/passwords/group.file<br />
  296.       Require Group admins
  297.     </code></p></div>
  298.  
  299.     <p>Note that <code>AllowOverride AuthConfig</code> must be in effect
  300.     for these directives to have any effect.</p>
  301.  
  302.     <p>Please see the <a href="auth.html">authentication tutorial</a> for a
  303.     more complete discussion of authentication and authorization.</p>
  304. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  305. <div class="section">
  306. <h2><a name="ssi" id="ssi">Server Side Includes example</a></h2>
  307.  
  308.     <p>Another common use of <code>.htaccess</code> files is to enable
  309.     Server Side Includes for a particular directory. This may be done with
  310.     the following configuration directives, placed in a
  311.     <code>.htaccess</code> file in the desired directory:</p>
  312.  
  313.     <div class="example"><p><code>
  314.        Options +Includes<br />
  315.        AddType text/html shtml<br />
  316.        AddHandler server-parsed shtml
  317.     </code></p></div>
  318.  
  319.     <p>Note that <code>AllowOverride Options</code> and <code>AllowOverride
  320.     FileInfo</code> must both be in effect for these directives to have any
  321.     effect.</p>
  322.  
  323.     <p>Please see the <a href="ssi.html">SSI tutorial</a> for a more
  324.     complete discussion of server-side includes.</p>
  325. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  326. <div class="section">
  327. <h2><a name="cgi" id="cgi">CGI example</a></h2>
  328.  
  329.     <p>Finally, you may wish to use a <code>.htaccess</code> file to permit
  330.     the execution of CGI programs in a particular directory. This may be
  331.     implemented with the following configuration:</p>
  332.  
  333.     <div class="example"><p><code>
  334.        Options +ExecCGI<br />
  335.        AddHandler cgi-script cgi pl
  336.     </code></p></div>
  337.  
  338.     <p>Alternately, if you wish to have all files in the given directory be
  339.     considered to be CGI programs, this may be done with the following
  340.     configuration:</p>
  341.  
  342.     <div class="example"><p><code>
  343.        Options +ExecCGI<br />
  344.        SetHandler cgi-script
  345.     </code></p></div>
  346.  
  347.     <p>Note that <code>AllowOverride Options</code> and <code>AllowOverride
  348.     FileInfo</code> must both be in effect for these directives to have any
  349.     effect.</p>
  350.  
  351.     <p>Please see the <a href="cgi.html">CGI tutorial</a> for a more
  352.     complete discussion of CGI programming and configuration.</p>
  353.  
  354. </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  355. <div class="section">
  356. <h2><a name="troubleshoot" id="troubleshoot">Troubleshooting</a></h2>
  357.  
  358.     <p>When you put configuration directives in a <code>.htaccess</code>
  359.     file, and you don't get the desired effect, there are a number of
  360.     things that may be going wrong.</p>
  361.  
  362.     <p>Most commonly, the problem is that <code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code> is not
  363.     set such that your configuration directives are being honored. Make
  364.     sure that you don't have a <code>AllowOverride None</code> in effect
  365.     for the file scope in question. A good test for this is to put garbage
  366.     in your <code>.htaccess</code> file and reload. If a server error is
  367.     not generated, then you almost certainly have <code>AllowOverride
  368.     None</code> in effect.</p>
  369.  
  370.     <p>If, on the other hand, you are getting server errors when trying to
  371.     access documents, check your Apache error log. It will likely tell you
  372.     that the directive used in your <code>.htaccess</code> file is not
  373.     permitted. Alternately, it may tell you that you had a syntax error,
  374.     which you will then need to fix.</p>
  375.  
  376. </div></div>
  377. <div class="bottomlang">
  378. <p><span>Available Languages: </span><a href="../en/howto/htaccess.html" title="English"> en </a> |
  379. <a href="../ja/howto/htaccess.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
  380. <a href="../ko/howto/htaccess.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
  381. <a href="../pt-br/howto/htaccess.html" hreflang="pt-br" rel="alternate" title="PortuguΩs (Brasil)"> pt-br </a></p>
  382. </div><div id="footer">
  383. <p class="apache">Copyright 2007 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
  384. <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>
  385. </body></html>