SHARE
Facebook X Pinterest WhatsApp

Using .htaccess Files with Apache Page 2

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



The name ‘.htaccess‘ isn’t universally acceptable, though.
Sometimes it can quite difficult to persuade a system to let you create
or edit a file with such a name. For this reason, you can change the
name that Apache will use when looking for these per-directory
config files by using the AccessFileName directive in your
server’s httpd.conf file. For instance,

  
    AccessFileName ht.acl
  

will cause Apache to look for files named ht.acl instead
of .htaccess. They'll be treated the same way, though,
and they're still called '.htaccess files' for
convenience.

Locating and Merging .htaccess
Files

When Apache determines that a requested resource actually represents
a file on the disk, it starts a process called the 'directory walk.'
This involves checking through its internal list of
containers to find those that apply,
and possibly searching the directories on the filesystem for
.htaccess files.

Each time the directory walk finds a new set of directives that apply
to the request, they are merged with the settings already
accumulated. The result is a collection of settings that apply to
the final document, culled from all of its ancestor directories and
the server's config files.

When searching for .htaccess files, Apache starts at the
top of the filesystem. (On Windows, that usually means 'C:';
otherwise, the root directory '/'.) It then walks down the
directories to the one containing the final document, processing and merging
any .htaccess files it finds that the config files say should
be processed. (See the section on overrides
for more information on how the server determines whether an
.htaccess file should be processed or not.)

This can be an intensive process. Consider a request for

which resolves to the file

    C:Program FilesApache GroupApachehtdocsfoobargritchx.html
  

Unless instructed otherwise, Apache is going to look for each of the
following .htaccess files, and process any it finds:

  1. C:.htaccess
  2. C:Program Files.htaccess
  3. C:Program FilesApache Group.htaccess
  4. C:Program FilesApache GroupApache.htaccess
  5. C:Program FilesApache GroupApachehtdocs.htaccess
  6. C:Program FilesApache GroupApachehtdocsfoo.htaccess
  7. C:Program FilesApache GroupApachehtdocsfoobar.htaccess
  8. C:Program FilesApache GroupApachehtdocsfoobargritch.htaccess

That's a lot of work just to return a single file! And the server will
repeat this process each and every time the file is requested. See
the overrides section for a way to reduce
this overhead with the AllowOverride None
directive.

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.