summaryrefslogtreecommitdiffstats
path: root/docs/manual/rewrite/intro.html.en
diff options
context:
space:
mode:
Diffstat (limited to 'docs/manual/rewrite/intro.html.en')
-rw-r--r--docs/manual/rewrite/intro.html.en152
1 files changed, 94 insertions, 58 deletions
diff --git a/docs/manual/rewrite/intro.html.en b/docs/manual/rewrite/intro.html.en
index 9e9963d..c37be63 100644
--- a/docs/manual/rewrite/intro.html.en
+++ b/docs/manual/rewrite/intro.html.en
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
-<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
+<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<!--
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This file is generated from xml source: DO NOT EDIT
@@ -24,7 +24,7 @@
<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.4</a> &gt; <a href="./">Rewrite</a></div><div id="page-content"><div id="preamble"><h1>Apache mod_rewrite Introduction</h1>
<div class="toplang">
<p><span>Available Languages: </span><a href="../en/rewrite/intro.html" title="English">&nbsp;en&nbsp;</a> |
-<a href="../fr/rewrite/intro.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
+<a href="../fr/rewrite/intro.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
</div>
<p>This document supplements the <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>
@@ -73,7 +73,7 @@ it will tell you exactly how each rule is processed.</p>
<div class="section">
<h2><a name="regex" id="regex">Regular Expressions</a></h2>
-<p>mod_rewrite uses the <a href="http://pcre.org/">Perl Compatible
+<p><code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> uses the <a href="http://pcre.org/">Perl Compatible
Regular Expression</a> vocabulary. In this document, we do not attempt
to provide a detailed reference to regular expressions. For that, we
recommend the <a href="http://pcre.org/pcre.txt">PCRE man pages</a>, the
@@ -101,32 +101,65 @@ well as write your own.</p>
<th>Example</th>
</tr>
-<tr><td><code>.</code></td><td>Matches any single
-character</td><td><code>c.t</code> will match <code>cat</code>,
-<code>cot</code>, <code>cut</code>, etc.</td></tr>
-<tr><td><code>+</code></td><td>Repeats the previous match one or more
-times</td><td><code>a+</code> matches <code>a</code>, <code>aa</code>,
-<code>aaa</code>, etc</td></tr>
-<tr><td><code>*</code></td><td>Repeats the previous match zero or more
-times.</td><td><code>a*</code> matches all the same things
-<code>a+</code> matches, but will also match an empty string.</td></tr>
-<tr><td><code>?</code></td><td>Makes the match optional.</td><td>
-<code>colou?r</code> will match <code>color</code> and <code>colour</code>.</td>
+<tr>
+ <td><code>.</code></td>
+ <td>Matches any single character</td>
+ <td><code>c.t</code> will match <code>cat</code>, <code>cot</code>,
+ <code>cut</code>, etc</td>
+</tr>
+<tr>
+ <td><code>+</code></td>
+ <td>Repeats the previous match one or more times</td>
+ <td><code>a+</code> matches <code>a</code>, <code>aa</code>,
+ <code>aaa</code>, etc</td>
+</tr>
+<tr>
+ <td><code>*</code></td>
+ <td>Repeats the previous match zero or more times</td>
+ <td><code>a*</code> matches all the same things <code>a+</code> matches,
+ but will also match an empty string</td>
+</tr>
+<tr>
+ <td><code>?</code></td>
+ <td>Makes the match optional</td>
+ <td><code>colou?r</code> will match <code>color</code> and
+ <code>colour</code></td>
+</tr>
+<tr>
+ <td><code>\</code></td>
+ <td>Escape the next character</td>
+ <td><code>\.</code> will match <code>.</code> (dot) and not <em>any single
+ character</em> as explain above</td>
+</tr>
+<tr>
+ <td><code>^</code></td>
+ <td>Called an anchor, matches the beginning of the string</td>
+ <td><code>^a</code> matches a string that begins with <code>a</code></td>
+</tr>
+<tr>
+ <td><code>$</code></td>
+ <td>The other anchor, this matches the end of the string</td>
+ <td><code>a$</code> matches a string that ends with <code>a</code></td>
+</tr>
+<tr>
+ <td><code>( )</code></td>
+ <td>Groups several characters into a single unit, and captures a match
+ for use in a backreference</td>
+ <td><code>(ab)+</code> matches <code>ababab</code> - that is, the
+ <code>+</code> applies to the group. For more on backreferences see
+ <a href="#InternalBackRefs">below</a></td>
</tr>
-<tr><td><code>^</code></td><td>Called an anchor, matches the beginning
-of the string</td><td><code>^a</code> matches a string that begins with
-<code>a</code></td></tr>
-<tr><td><code>$</code></td><td>The other anchor, this matches the end of
-the string.</td><td><code>a$</code> matches a string that ends with
-<code>a</code>.</td></tr>
-<tr><td><code>( )</code></td><td>Groups several characters into a single
-unit, and captures a match for use in a backreference.</td><td><code>(ab)+</code>
-matches <code>ababab</code> - that is, the <code>+</code> applies to the group.
-For more on backreferences see <a href="#InternalBackRefs">below</a>.</td></tr>
-<tr><td><code>[ ]</code></td><td>A character class - matches one of the
-characters</td><td><code>c[uoa]t</code> matches <code>cut</code>,
-<code>cot</code> or <code>cat</code>.</td></tr>
-<tr><td><code>[^ ]</code></td><td>Negative character class - matches any character not specified</td><td><code>c[^/]t</code> matches <code>cat</code> or <code>c=t</code> but not <code>c/t</code></td></tr>
+<tr>
+ <td><code>[ ]</code></td>
+ <td>A character class - matches one of the characters</td>
+ <td><code>c[uoa]t</code> matches <code>cut</code>, <code>cot</code> or
+ <code>cat</code></td>
+</tr>
+<tr>
+ <td><code>[^ ]</code></td>
+ <td>Negative character class - matches any character not specified</td>
+ <td><code>c[^/]t</code> matches <code>cat</code> or <code>c=t</code> but
+ not <code>c/t</code></td></tr>
</table>
<p>In <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> the <code>!</code> character can be
@@ -143,21 +176,21 @@ the expression.</p>
<em>CondPattern</em>, back-references are internally created
which can be used with the strings <code>$N</code> and
<code>%N</code> (see below). These are available for creating
- the <em>Substitution</em> parameter of a
+ the <em>Substitution</em> parameter of a
<code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> or
- the <em>TestString</em> parameter of a
+ the <em>TestString</em> parameter of a
<code class="directive"><a href="../mod/mod_rewrite.html#rewritecond">RewriteCond</a></code>.</p>
- <p> Captures in the <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> patterns are (counterintuitively) available to
- all preceding
+ <p> Captures in the <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> patterns are (counterintuitively) available to
+ all preceding
<code class="directive"><a href="../mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> directives,
because the <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>
expression is evaluated before the individual conditions.</p>
- <p>Figure 1 shows to which
- locations the back-references are transferred for expansion as
- well as illustrating the flow of the RewriteRule, RewriteCond
- matching. In the next chapters, we will be exploring how to use
- these back-references, so do not fret if it seems a bit alien
+ <p>Figure 1 shows to which
+ locations the back-references are transferred for expansion as
+ well as illustrating the flow of the RewriteRule, RewriteCond
+ matching. In the next chapters, we will be exploring how to use
+ these back-references, so do not fret if it seems a bit alien
to you at first.
</p>
@@ -179,12 +212,12 @@ of three arguments separated by spaces. The arguments are</p>
<li><var>[flags]</var>: options affecting the rewritten request.</li>
</ol>
-<p>The <var>Pattern</var> is a <a href="#regex">regular expression</a>.
-It is initially (for the first rewrite rule or until a substitution occurs)
-matched against the URL-path of the incoming request (the part after the
-hostname but before any question mark indicating the beginning of a query
-string) or, in per-directory context, against the request's path relative
-to the directory for which the rule is defined. Once a substitution has
+<p>The <var>Pattern</var> is a <a href="#regex">regular expression</a>.
+It is initially (for the first rewrite rule or until a substitution occurs)
+matched against the URL-path of the incoming request (the part after the
+hostname but before any question mark indicating the beginning of a query
+string) or, in per-directory context, against the request's path relative
+to the directory for which the rule is defined. Once a substitution has
occurred, the rules that follow are matched against the substituted
value.
</p>
@@ -198,25 +231,26 @@ value.
<p>The <var>Substitution</var> can itself be one of three things:</p>
<dl>
-<dt>A full filesystem path to a resource</dt>
+<dt>1. A full filesystem path to a resource</dt>
<dd>
-<pre class="prettyprint lang-config">RewriteRule "^/games" "/usr/local/games/web"</pre>
+<pre class="prettyprint lang-config">RewriteRule "^/games" "/usr/local/games/web/puzzles.html"</pre>
<p>This maps a request to an arbitrary location on your filesystem, much
like the <code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code> directive.</p>
</dd>
-<dt>A web-path to a resource</dt>
+<dt>2. A web-path to a resource</dt>
<dd>
-<pre class="prettyprint lang-config">RewriteRule "^/foo$" "/bar"</pre>
+<pre class="prettyprint lang-config">RewriteRule "^/games$" "/puzzles.html"</pre>
<p>If <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> is set
to <code>/usr/local/apache2/htdocs</code>, then this directive would
-map requests for <code>http://example.com/foo</code> to the
-path <code>/usr/local/apache2/htdocs/bar</code>.</p>
+map requests for <code>http://example.com/games</code> to the
+path <code>/usr/local/apache2/htdocs/puzzles.html</code>.</p>
+
</dd>
-<dt>An absolute URL</dt>
+<dt>3. An absolute URL</dt>
<dd>
<pre class="prettyprint lang-config">RewriteRule "^/product/view$" "http://site2.example.com/seeproduct.html" [R]</pre>
@@ -224,6 +258,8 @@ path <code>/usr/local/apache2/htdocs/bar</code>.</p>
</dd>
</dl>
+<div class="warning">Note that <strong>1</strong> and <strong>2</strong> have exactly the same syntax. The difference between them is that in the case of <strong>1</strong>, the top level of the target path (i.e., <code>/usr/</code>) exists on the filesystem, where as in the case of <strong>2</strong>, it does not. (i.e., there's no <code>/bar/</code> as a root-level directory in the filesystem.)</div>
+
<p>The <var>Substitution</var> can also
contain <em>back-references</em> to parts of the incoming URL-path
matched by the <var>Pattern</var>. Consider the following:</p>
@@ -275,7 +311,7 @@ argument is a list of flags that modify how the match is evaluated.</p>
<p>For example, to send all requests from a particular IP range to a
different server, you could use:</p>
<pre class="prettyprint lang-config">RewriteCond "%{REMOTE_ADDR}" "^10\.2\."
-RewriteRule "(.*)" "http://intranet.example.com$1"</pre>
+RewriteRule "(.*)" "http://intranet.example.com$1"</pre>
<p>When more than
@@ -286,8 +322,8 @@ applied. For example, to deny requests that contain the word "hack" in
their query string, unless they also contain a cookie containing
the word "go", you could use:</p>
<pre class="prettyprint lang-config">RewriteCond "%{QUERY_STRING}" "hack"
-RewriteCond "%{HTTP_COOKIE}" "!go"
-RewriteRule "." "-" [F]</pre>
+RewriteCond "%{HTTP_COOKIE}" !go
+RewriteRule "." "-" [F]</pre>
<p>Notice that the exclamation mark specifies a negative match, so the rule is only applied if the cookie does not contain "go".</p>
@@ -299,7 +335,7 @@ variables <code>%1</code>, <code>%2</code>, etc. For example, this
will direct the request to a different directory depending on the
hostname used to access the site:</p>
<pre class="prettyprint lang-config">RewriteCond "%{HTTP_HOST}" "(.*)"
-RewriteRule "^/(.*)" "/sites/%1/$1"</pre>
+RewriteRule "^/(.*)" "/sites/%1/$1"</pre>
<p>If the request was for <code>http://example.com/foo/bar</code>,
then <code>%1</code> would contain <code>example.com</code>
@@ -336,8 +372,8 @@ the <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">Rewrit
</div></div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="../en/rewrite/intro.html" title="English">&nbsp;en&nbsp;</a> |
-<a href="../fr/rewrite/intro.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
-</div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
+<a href="../fr/rewrite/intro.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
+</div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Libera.chat, or sent to our <a href="https://httpd.apache.org/lists.html">mailing lists</a>.</div>
<script type="text/javascript"><!--//--><![CDATA[//><!--
var comments_shortname = 'httpd';
var comments_identifier = 'http://httpd.apache.org/docs/2.4/rewrite/intro.html';
@@ -355,7 +391,7 @@ var comments_identifier = 'http://httpd.apache.org/docs/2.4/rewrite/intro.html';
}
})(window, document);
//--><!]]></script></div><div id="footer">
-<p class="apache">Copyright 2019 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>
+<p class="apache">Copyright 2024 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>
<p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
if (typeof(prettyPrint) !== 'undefined') {
prettyPrint();