Commit 1d4afcd0 authored by Richard Bowen's avatar Richard Bowen
Browse files

Adds more discussion of several rewrite flags.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@421068 13f79535-47bb-0310-9956-ffa450edef68
parent 9b892c06
Loading
Loading
Loading
Loading
+47 −3
Original line number Diff line number Diff line
@@ -114,7 +114,21 @@ an example, not as a recommendation.</p>


<h3><a name="flag_f" id="flag_f">F|forbidden</a></h3>
<p>Forbidden flag</p>
<p>Using the [F] flag causes Apache to return a 403 Forbidden status
code to the client. While the same behavior can be accomplished using
the <code class="directive"><a href="../mod/mod_access.html#deny">Deny</a></code> directive, this 
allows more flexibility in assigning a Forbidden status.</p>

<p>The following rule will forbid <code>.exe</code> files from being
downloaded from your server.</p>

<div class="example"><p><code>
RewriteRule \.exe - [F]
</code></p></div>

<p>This rule uses the "-" syntax for the rewrite target, which means
that the requested URI is not modified.</p>



<h3><a name="flag_g" id="flag_g">G|gone</a></h3>
@@ -134,7 +148,18 @@ an example, not as a recommendation.</p>


<h3><a name="flag_nc" id="flag_nc">NC|nocase</a></h3>
<p>No case flag</p>
<p>Use of the [NC] flag causes the <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> to be matched in a
case-insensitive manner. That is, it doesn't care whether letters appear
as upper-case or lower-case in the matched URI.</p>

<p>In the example below, any request for an image file will be proxied
to your dedicated image server. The match is case-insensitive, so that
<code>.jpg</code> and <code>.JPG</code> files are both acceptable, for
example.</p>

<div class="example"><p><code>
RewriteRule (.*\.(jpg|gif|png))$ http://images.example.com$1 [P,NC]
</code></p></div>


<h3><a name="flag_ne" id="flag_ne">NE|noescape</a></h3>
@@ -166,7 +191,26 @@ an example, not as a recommendation.</p>


<h3><a name="flag_s" id="flag_s">S|skip</a></h3>
<p>Skip flag</p>
<p>The [S] flag is used to skip rules that you don't want to run. This
can be thought of as a <code>goto</code> statement in your rewrite
ruleset. In the following example, we only want to run the <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> if the requested URI
doesn't correspond with an actual file.</p>

<div class="example"><p><code>
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteRule .? - [S=2]<br />
<br />
RewriteRule (.*\.gif) images.php?$1<br />
RewriteRule (.*\.html) docs.php?$1
</code></p></div>

<p>This technique is useful because a <code class="directive"><a href="../mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> only applies to the
<code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> immediately
following it. Thus, if you want to make a <code>RewriteCond</code> apply
to several <code>RewriteRule</code>s, one possible technique is to
negate those conditions and use a [Skip] flag.</p>



<h3><a name="flag_t" id="flag_t">T|type</a></h3>
+50 −3
Original line number Diff line number Diff line
@@ -122,7 +122,21 @@ an example, not as a recommendation.</p>
</section>

<section id="flag_f"><title>F|forbidden</title>
<p>Forbidden flag</p>
<p>Using the [F] flag causes Apache to return a 403 Forbidden status
code to the client. While the same behavior can be accomplished using
the <directive module="mod_access">Deny</directive> directive, this 
allows more flexibility in assigning a Forbidden status.</p>

<p>The following rule will forbid <code>.exe</code> files from being
downloaded from your server.</p>

<example>
RewriteRule \.exe - [F]
</example>

<p>This rule uses the "-" syntax for the rewrite target, which means
that the requested URI is not modified.</p>

</section>

<section id="flag_g"><title>G|gone</title>
@@ -142,7 +156,19 @@ an example, not as a recommendation.</p>
</section>

<section id="flag_nc"><title>NC|nocase</title>
<p>No case flag</p>
<p>Use of the [NC] flag causes the <directive
module="mod_rewrite">RewriteRule</directive> to be matched in a
case-insensitive manner. That is, it doesn't care whether letters appear
as upper-case or lower-case in the matched URI.</p>

<p>In the example below, any request for an image file will be proxied
to your dedicated image server. The match is case-insensitive, so that
<code>.jpg</code> and <code>.JPG</code> files are both acceptable, for
example.</p>

<example>
RewriteRule (.*\.(jpg|gif|png))$ http://images.example.com$1 [P,NC]
</example>
</section>

<section id="flag_ne"><title>NE|noescape</title>
@@ -174,7 +200,28 @@ an example, not as a recommendation.</p>
</section>

<section id="flag_s"><title>S|skip</title>
<p>Skip flag</p>
<p>The [S] flag is used to skip rules that you don't want to run. This
can be thought of as a <code>goto</code> statement in your rewrite
ruleset. In the following example, we only want to run the <directive
module="mod_rewrite">RewriteRule</directive> if the requested URI
doesn't correspond with an actual file.</p>

<example>
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteRule .? - [S=2]<br />
<br />
RewriteRule (.*\.gif) images.php?$1<br />
RewriteRule (.*\.html) docs.php?$1
</example>

<p>This technique is useful because a <directive
module="mod_rewrite">RewriteCond</directive> only applies to the
<directive module="mod_rewrite">RewriteRule</directive> immediately
following it. Thus, if you want to make a <code>RewriteCond</code> apply
to several <code>RewriteRule</code>s, one possible technique is to
negate those conditions and use a [Skip] flag.</p>

</section>

<section id="flag_t"><title>T|type</title>
+15 −3
Original line number Diff line number Diff line
@@ -145,13 +145,25 @@ examples.
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="flags" id="flags">Rewrite Flags</a></h2>
<p>Discussion of the flags to RewriteRule, and when and why one might
use them.</p>
<p>The behavior of a <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> can be modified by the
application of one more flags to the end of the rule. For example, the
matching behavior of a rule can be made case-insensitive by the
application of the <code>[NC]</code> flag:
</p>
<div class="example"><p><code>
RewriteRule ^puppy.html smalldog.html [NC]
</code></p></div>

<p>For more details on the available flags, their meanings, and
examples, see the <a href="flags.html">Rewrite Flags</a> document.</p>

</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="rewritecond" id="rewritecond">Rewrite conditions</a></h2>
<p>Discussion of RewriteCond, looping, and other related concepts.
<p>The <code class="directive"><a href="../mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> directive
allows a condition to be applied to a <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>.
</p>

</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="rewritemap" id="rewritemap">Rewrite maps</a></h2>
+18 −3
Original line number Diff line number Diff line
@@ -148,13 +148,28 @@ examples.
</section>

<section id="flags"><title>Rewrite Flags</title>
<p>Discussion of the flags to RewriteRule, and when and why one might
use them.</p>
<p>The behavior of a <directive
module="mod_rewrite">RewriteRule</directive> can be modified by the
application of one more flags to the end of the rule. For example, the
matching behavior of a rule can be made case-insensitive by the
application of the <code>[NC]</code> flag:
</p>
<example>
RewriteRule ^puppy.html smalldog.html [NC]
</example>

<p>For more details on the available flags, their meanings, and
examples, see the <a href="flags.html">Rewrite Flags</a> document.</p>

</section>


<section id="rewritecond"><title>Rewrite conditions</title>
<p>Discussion of RewriteCond, looping, and other related concepts.
<p>The <directive module="mod_rewrite">RewriteCond</directive> directive
allows a condition to be applied to a <directive
module="mod_rewrite">RewriteRule</directive>.
</p>

</section>

<section id="rewritemap"><title>Rewrite maps</title>