<note>You should avoid using <code>.htaccess</code> files completely if you have access to
httpd main server config file. Using <code>.htaccess</code> files slows down your Apache server.
Any directive that you can include in a <code>.htaccess</code> file is
better set in a <directivemodule="core">Directory</directive> block,
as it will have the same effect with better performance.</note>
httpd main server config file. Using <code>.htaccess</code> files slows down your Apache http server.
Any directive that you can include in a <code>.htaccess</code> file is better set in a <directivemodule="core">Directory</directive> block, as it will have the same effect with better performance.</note>
</section>
<sectionid="what">
@@ -129,13 +126,16 @@ changes on a per-directory basis.</p>
<sectionid="when"><title>When (not) to use .htaccess files</title>
<p>In general, you should never use <code>.htaccess</code> files unless
<p>In general, you should only use <code>.htaccess</code> files when
you don't have access to the main server configuration file. There is,
for example, a prevailing misconception that user authentication should
always be done in <code>.htaccess</code> files. This is simply not the
for example, a common misconception that user authentication should
always be done in <code>.htaccess</code> files, and, in more recent years,
another miscomception that <module>mod_rewrite</module> directives
must go in <code>.htaccess</code> files. This is simply not the
case. You can put user authentication configurations in the main server
configuration, and this is, in fact, the preferred way to do
things.</p>
things. Likewise, <code>mod_rewrite</code> directives work better,
in many respects, in the main server configuration.</p>
<p><code>.htaccess</code> files should be used in a case where the
content providers need to make configuration changes to the server on a
@@ -159,18 +159,18 @@ changes on a per-directory basis.</p>
<p>The first of these is performance. When <directive
module="core">AllowOverride</directive>
is set to allow the use of <code>.htaccess</code> files, Apache will
is set to allow the use of <code>.htaccess</code> files, httpd will
look in every directory for <code>.htaccess</code> files. Thus,
permitting <code>.htaccess</code> files causes a performance hit,
whether or not you actually even use them! Also, the
<code>.htaccess</code> file is loaded every time a document is
requested.</p>
<p>Further note that Apache must look for <code>.htaccess</code> files
<p>Further note that httpd must look for <code>.htaccess</code> files
in all higher-level directories, in order to have a full complement of
directives that it must apply. (See section on <ahref="#how">how
directives are applied</a>.) Thus, if a file is requested out of a
directory <code>/www/htdocs/example</code>, Apache must look for the
directory <code>/www/htdocs/example</code>, httpd must look for the
following files:</p>
<example>
@@ -186,6 +186,17 @@ changes on a per-directory basis.</p>
<code>.htaccess</code> files were enabled for <code>/</code>, which
is not usually the case.)</p>
<p>In the case of <directive
module="mod_rewrite">RewriteRule</directive> directives, in
<code>.htaccess</code> context these regular expressions must be
re-compiled with every request to the directory, whereas in main
server configuration context they are compiled once and cached.
Additionally, the rules themselves are more complicated, as one must
work around the restrictions that come with per-directory context
and <code>mod_rewrite</code>. Consult the <a
href="../rewrite/intro.html#htaccess">Rewrite Guide</a> for more
detail on this subject.</p>
<p>The second consideration is one of security. You are permitting
users to modify server configuration, which may result in changes over
which you have no control. Carefully consider whether you want to give
@@ -207,7 +218,7 @@ changes on a per-directory basis.</p>