SHARE
Facebook X Pinterest WhatsApp

Using .htaccess Files with Apache Page 3

Written By
thumbnail Ken Coar
Ken Coar
Jul 19, 2000
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



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

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

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.

thumbnail Ken Coar

Ken Coar is a ServerWatch contributor.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.