as well as <code><a href="core.html#accessfilename">.htaccess</a>
</code> files to control access to particular parts of the server.
Access can be controlled based on the client hostname, IP address, or
other characteristics of the client request, as captured in <a href="../env.html">environment variables</a>. The <code class="directive"><a href="#allow">Allow</a></code> and <code class="directive"><a href="#deny">Deny</a></code> directives are used to
specify which clients are or are not allowed access to the server,
while the <code class="directive"><a href="#order">Order</a></code>
directive sets the default access state, and configures how the
<code class="directive"><a href="#allow">Allow</a></code> and <code class="directive"><a href="#deny">Deny</a></code> directives interact with each
other.</p>
<p>Both host-based access restrictions and password-based
authentication may be implemented simultaneously. In that case,
the <code class="directive"><a href="../mod/core.html#satisfy">Satisfy</a></code> directive is used
to determine how the two sets of restrictions interact.</p>
<p>In general, access restriction directives apply to all
<p>The <code class="directive">Allow</code> directive affects which hosts can
access an area of the server. Access can be controlled by
hostname, IP address, IP address range, or by other
characteristics of the client request captured in environment
variables.</p>
<p>The first argument to this directive is always
<code>from</code>. The subsequent arguments can take three
different forms. If <code>Allow from all</code> is specified, then
all hosts are allowed access, subject to the configuration of the
<code class="directive"><a href="#deny">Deny</a></code> and <code class="directive"><a href="#order">Order</a></code> directives as discussed
below. To allow only particular hosts or groups of hosts to access
the server, the <em>host</em> can be specified in any of the
following formats:</p>
<dl>
<dt>A (partial) domain-name</dt>
<dd>
<div class="example"><h3>Example:</h3><p><code>
Allow from apache.org<br />
Allow from .net example.edu
</code></p></div>
<p>Hosts whose names match, or end in, this string are allowed
access. Only complete components are matched, so the above
example will match <code>foo.apache.org</code> but it will not
match <code>fooapache.org</code>. This configuration will cause
Apache to perform a double reverse DNS lookup on the client IP
address, regardless of the setting of the <code class="directive"><a href="../mod/core.html#hostnamelookups">HostnameLookups</a></code> directive. It will do
a reverse DNS lookup on the IP address to find the associated
hostname, and then do a forward lookup on the hostname to assure
that it matches the original IP address. Only if the forward
and reverse DNS are consistent and the hostname matches will
access be allowed.</p></dd>
<dt>A full IP address</dt>
<dd>
<div class="example"><h3>Example:</h3><p><code>
Allow from 10.1.2.3<br />
Allow from 192.168.1.104 192.168.1.205
</code></p></div>
<p>An IP address of a host allowed access</p></dd>
<dt>A partial IP address</dt>
<dd>
<div class="example"><h3>Example:</h3><p><code>
Allow from 10.1<br />
Allow from 10 172.20 192.168.2
</code></p></div>
<p>The first 1 to 3 bytes of an IP address, for subnet
restriction.</p></dd>
<dt>A network/netmask pair</dt>
<dd>
<div class="example"><h3>Example:</h3><p><code>
Allow from 10.1.0.0/255.255.0.0
</code></p></div>
<p>A network a.b.c.d, and a netmask w.x.y.z. For more
fine-grained subnet restriction.</p></dd>
<dt>A network/nnn CIDR specification</dt>
<dd>
<div class="example"><h3>Example:</h3><p><code>
Allow from 10.1.0.0/16
</code></p></div>
<p>Similar to the previous case, except the netmask consists of
nnn high-order 1 bits.</p></dd>
</dl>
<p>Note that the last three examples above match exactly the
same set of hosts.</p>
<p>IPv6 addresses and IPv6 subnets can be specified as shown
below:</p>
<div class="example"><p><code>
Allow from 2001:db8::a00:20ff:fea7:ccea<br />
Allow from 2001:db8::a00:20ff:fea7:ccea/10
</code></p></div>
<p>The third format of the arguments to the
<code class="directive">Allow</code> directive allows access to the server
to be controlled based on the existence of an <a href="../env.html">environment variable</a>. When <code>Allow from
env=<var>env-variable</var></code> is specified, then the request is
allowed access if the environment variable <var>env-variable</var>
exists. The server provides the ability to set environment
variables in a flexible way based on characteristics of the client
request using the directives provided by
<code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code>. Therefore, this directive can be
used to allow access based on such factors as the clients
<code>User-Agent</code> (browser type), <code>Referer</code>, or
<p>The <code class="directive">Order</code> directive, along with the
<code class="directive"><a href="#allow">Allow</a></code> and <code class="directive"><a href="#deny">Deny</a></code> directives, controls a
three-pass access control system. The first pass processes either
all <code class="directive"><a href="#allow">Allow</a></code> or all
<code class="directive"><a href="#deny">Deny</a></code> directives, as
specified by the <code class="directive">Order</code> directive. The second
pass parses the rest of the directives (<code class="directive"><a href="#deny">Deny</a></code> or <code class="directive"><a href="#allow">Allow</a></code>). The third pass applies
to all requests which do not match either of the first two.</p>
<p>Note that all <code class="directive"><a href="#allow">Allow</a></code> and <code class="directive"><a href="#deny">Deny</a></code> directives are processed,
unlike a typical firewall, where only the first match is used. The
last match is effective (also unlike a typical firewall).
Additionally, the order in which lines appear in the configuration
files is not significant -- all <code class="directive"><a href="#allow">Allow</a></code> lines are processed as one
group, all <code class="directive"><a href="#deny">Deny</a></code> lines
are considered as another, and the default state is considered by
itself.</p>
<p><em>Ordering</em> is one of:</p>
<dl>
<dt><code>Allow,Deny</code></dt>
<dd>First, all <code class="directive"><a href="#allow">Allow</a></code> directives are
evaluated; at least one must match, or the request is rejected.
Next, all <code class="directive"><a href="#deny">Deny</a></code>
directives are evaluated. If any matches, the request is rejected.
Last, any requests which do not match an <code class="directive"><a href="#allow">Allow</a></code> or a <code class="directive"><a href="#deny">Deny</a></code> directive are denied by
default.</dd>
<dt><code>Deny,Allow</code></dt>
<dd>First, all <code class="directive"><a href="#deny">Deny</a></code>
directives are evaluated; if any match, the request is denied
<strong>unless</strong> it also matches an <code class="directive"><a href="#allow">Allow</a></code> directive. Any requests
which do not match any <code class="directive"><a href="#allow">Allow</a></code> or <code class="directive"><a href="#deny">Deny</a></code> directives are
permitted.</dd>
<dt><code>Mutual-failure</code></dt>
<dd>This order has the same effect as <code>Order
Allow,Deny</code> and is deprecated in its favor.</dd>
</dl>
<p>Keywords may only be separated by a comma; <em>no whitespace</em>
is allowed between them.</p>
<table class="bordered">
<tr>
<th>Match</th>
<th>Allow,Deny result</th>
<th>Deny,Allow result</th>
</tr><tr>
<th>Match Allow only</th>
<td>Request allowed</td>
<td>Request allowed</td>
</tr><tr>
<th>Match Deny only</th>
<td>Request denied</td>
<td>Request denied</td>
</tr><tr>
<th>No match</th>
<td>Default to second directive: Denied</td>
<td>Default to second directive: Allowed</td>
</tr><tr>
<th>Match both Allow & Deny</th>
<td>Final match controls: Denied</td>
<td>Final match controls: Allowed</td>
</tr>
</table>
<p>In the following example, all hosts in the apache.org domain
are allowed access; all other hosts are denied access.</p>
<div class="example"><p><code>
Order Deny,Allow<br />
Deny from all<br />
Allow from apache.org
</code></p></div>
<p>In the next example, all hosts in the apache.org domain are
allowed access, except for the hosts which are in the foo.apache.org
subdomain, who are denied access. All hosts not in the apache.org
domain are denied access because the default state is to <code class="directive"><a href="#deny">Deny</a></code> access to the server.</p>
<div class="example"><p><code>
Order Allow,Deny<br />
Allow from apache.org<br />
Deny from foo.apache.org
</code></p></div>
<p>On the other hand, if the <code class="directive">Order</code> in the
last example is changed to <code>Deny,Allow</code>, all hosts will
be allowed access. This happens because, regardless of the actual
ordering of the directives in the configuration file, the
<code>Allow from apache.org</code> will be evaluated last and will
override the <code>Deny from foo.apache.org</code>. All hosts not in
the <code>apache.org</code> domain will also be allowed access
because the default state is <code class="directive"><a href="#allow">Allow</a></code>.</p>
<p>The presence of an <code class="directive">Order</code> directive can
affect access to a part of the server even in the absence of
will always be evaluated after an <code class="directive"><a href="#allow">Allow</a></code> or <code class="directive"><a href="#deny">Deny</a></code> directive occurring in a
section or <code>.htaccess</code> file, regardless of the setting of
the <code class="directive">Order</code> directive. For details on the
merging of configuration sections, see the documentation on <a href="../sections.html">How Directory, Location and Files sections
work</a>.</p>
</div>
</div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="../en/mod/mod_authz_host.html" title="English"> en </a> |
<a href="../ja/mod/mod_authz_host.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
<a href="../ko/mod/mod_authz_host.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
</div><div id="footer">
<p class="apache">Copyright 2007 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>