GuidesUsing .htaccess Files with Apache Page 3

Using .htaccess Files with Apache Page 3

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

Directives that Work in .htaccess

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 .htaccess
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
config files.

The SetEnvIf Directive

Syntax: SetEnvIf attribute regex envar[=value]

Default: none

Context: server config, virtual host, directory,

Override: FileInfo

Status: Base

Module: mod_setenvif

Compatibility: Apache 1.3 and above; the
Request_Protocol keyword and environment-variable matching are only
available with 1.3.7 and later; use in .htaccess files only supported
with 1.3.13 and later

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

Get the Free Newsletter!
Subscribe to Daily Tech Insider for top news, trends & analysis
This email address is invalid.
Get the Free Newsletter!
Subscribe to Daily Tech Insider for top news, trends & analysis
This email address is invalid.

Latest Posts

Related Stories