2011年2月7日星期一

How Directory, Location and Files sections work

The sections , and can contain directives which only apply to specified directories, URLs or files respectively. Also htaccess files can be used inside a directory to apply directives to that directory. This document explains how these different sections differ and how they relate to each other when Apache decides which directives apply for a particular directory or request URL.

Directives allowed in the sections

Everything that is syntactically allowed in is also allowed in (except a sub- section). Semantically, however some things, most notably AllowOverride and the two options FollowSymLinks andSymLinksIfOwnerMatch, make no sense in , or . The same for -- syntactically everything is fine, but semantically some things are different.

How the sections are merged

The order of merging is:

  1. (except regular expressions) and .htaccess done simultaneously (with .htaccess, if allowed, overriding)
  2. , and with regular expressions
  3. and done simultaneously
  4. and done simultaneously

Apart from , each group is processed in the order that they appear in the configuration files. (group 1 above) is processed in the order shortest directory component to longest. If multiple sections apply to the same directory they are processed in the configuration file order. The configuration files are read in the order httpd.conf, srm.conf and access.conf. Configurations included via the Include directive will be treated as if they were inside the including file at the location of the Include directive.

Sections inside sections are applied after the corresponding sections outside the virtual host definition. This allows virtual hosts to override the main server configuration. (Note: this only works correctly from 1.2.2 and 1.3a2 onwards. Before those releases sections inside virtual hosts were applied before the main server).

Later sections override earlier ones.

Notes about using sections

The general guidelines are:

  • If you are attempting to match objects at the filesystem level then you must use and/or .
  • If you are attempting to match objects at the URL level then you must use

But a notable exception is:

  • proxy control is done via . This is a legacy mistake because the proxy existed prior to . A future version of the config language should probably switch this to .

Note about .htaccess parsing:

  • Modifying .htaccess parsing during Location doesn't do anything because .htaccess parsing has already occurred.

and symbolic links:

  • It is not possible to use "Options FollowSymLinks" or "Options SymLinksIfOwnerMatch" inside a , or section (the options are simply ignored). Using the options in question is only possible inside a section (or a .htaccess file).

and Options:

  • Apache won't check for it, but using an Options directive inside a section has no effect.

Another note:

  • There is actually a / sequence performed just before the name translation phase (whereAliases and DocumentRoots are used to map URLs to filenames). The results of this sequence are completely thrown away after the translation has completed.

没有评论:

发表评论