Using .htaccess Files with Apache Page 3
.htaccess files are evaluated for each request,
you don't need to reload the Apache server whenever you make a
change. This makes them particularly well suited for environments
with multiple groups or individuals sharing a single Web server
system; if the Webmaster allows, they can exercide control over
their own areas without nagging the Webmaster to reload Apache
with each change. Also, if there's a syntax error in an
.htaccess file, it only affects a portion of
the server's Web space, rather than keeping the server from
running at all (which is what would happen if the error was
in the server-wide config files).
Not all directives will work in
.htaccess files; for example,
it makes no sense to allow a
ServerName directive to appear
in one, since the server is already running and knows its name -- and
cannot change it -- by the time a request would cause the
.htaccess file to be read. Other directives aren't
allowed because they deal with features that are server-wide, or perhaps
are too sensitive.
However, most directives are allowed in
files. If you're not sure, take a look at the directive's documentation.
Figure 1 is a sample extracted from the Apache documentation. You can
see where the text says 'Context' that .htaccess is
listed; that means this directive can be used in the per-directory
The SetEnvIf Directive
Syntax: SetEnvIf attribute regex envar[=value]
|Figure 1: Directive Documentation|
Note, however, that there's more information on the Compatibility
line; it says that this directive can only be used in
.htaccess files if you're running Apache version 1.3.13 or
If you try to include a directive in an
file that isn't permitted there, any requests for documents under
that directory will result in a '
500 Server Error'
error page and a message in the server's error log.