summaryrefslogtreecommitdiff
path: root/docs/manual/mod/mod_rewrite.html.en
diff options
context:
space:
mode:
Diffstat (limited to 'docs/manual/mod/mod_rewrite.html.en')
-rw-r--r--docs/manual/mod/mod_rewrite.html.en178
1 files changed, 119 insertions, 59 deletions
diff --git a/docs/manual/mod/mod_rewrite.html.en b/docs/manual/mod/mod_rewrite.html.en
index a98e69a0..7c145cf6 100644
--- a/docs/manual/mod/mod_rewrite.html.en
+++ b/docs/manual/mod/mod_rewrite.html.en
@@ -8,11 +8,14 @@
<title>mod_rewrite - Apache HTTP Server</title>
<link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
-<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
+<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
+<script src="../style/scripts/prettify.js" type="text/javascript">
+</script>
+
<link href="../images/favicon.ico" rel="shortcut icon" /></head>
<body>
<div id="page-header">
-<p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</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>
<p class="apache">Apache HTTP Server Version 2.4</p>
<img alt="" src="../images/feather.gif" /></div>
<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
@@ -63,7 +66,7 @@ URLs on the fly</td></tr>
<h3>Topics</h3>
<ul id="topics">
<li><img alt="" src="../images/down.gif" /> <a href="#logging">Logging</a></li>
-</ul></div>
+</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="logging" id="logging">Logging</a></h2>
@@ -81,9 +84,10 @@ URLs on the fly</td></tr>
level higher than <code>trace2</code> only for debugging!
</div>
- <div class="example"><h3>Example</h3><p><code>
+ <div class="example"><h3>Example</h3><pre class="prettyprint lang-config">
LogLevel alert rewrite:trace3
- </code></p></div>
+ </pre>
+</div>
<div class="note"><h3>RewriteLog</h3>
<p>Those familiar with earlier versions of
@@ -112,38 +116,38 @@ URLs on the fly</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
</table>
- <p>The <code class="directive">RewriteBase</code> directive explicitly
- sets the base URL-path (not filesystem directory path!) for per-directory rewrites
- that result in the substitution of a relative path.
- When you use a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
- in a <code>.htaccess</code> file, <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> strips off
- the local directory prefix before processing, then rewrites the rest of
- the URL. When the rewrite is completed, <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>
- automatically adds the local directory prefix (or the
- <code class="directive">RewriteBase</code> when set) back on to the substitution
- before handing it back to the core of the server as if it were the original
- URL.</p>
-
- <p>This directive is <em>required</em> for per-directory rewrites whose context
- is a directory made available via the <code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code>
- directive, when the substitution uses a relative path.</p>
-
- <p>If your URL path does not exist verbatim on the filesystem,
- or isn't directly under your <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>,
- you must use <code class="directive">RewriteBase</code> in every
- <code>.htaccess</code> file where you want to use <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives.</p>
-
- <p>The example below demonstrates how to map
- http://example.com/myapp/index.html to
- /home/www/example/newsite.html, in a <code>.htaccess</code> file. This
- assumes that the content available at
- http://example.com/ is on disk at /home/www/example/</p>
-<div class="example"><pre>
-RewriteEngine On
-# The URL-path used to get to this context, not the filesystem path
-RewriteBase /myapp/
-RewriteRule ^index\.html$ newsite.html
-</pre></div>
+ <p>The <code class="directive">RewriteBase</code> directive specifies the
+ URL prefix to be used for per-directory (htaccess)
+ <code class="directive">RewriteRule</code> directives that substitute a relative
+ path.</p>
+ <p> This directive is <em>required</em> when you use a relative path
+ in a substitution in per-directory (htaccess) context unless either
+ of the following conditions are true:</p>
+ <ul>
+ <li> The original request, and the substitution, are underneath the
+ <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>
+ (as opposed to reachable by other means, such as
+ <code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code>).</li>
+ <li> The <em>filesystem</em> path to the directory containing the
+ <code class="directive">RewriteRule</code>, suffixed by the relative
+ substitution is also valid as a URL path on the server
+ (this is rare).</li>
+ </ul>
+
+<p> In the example below, <code class="directive">RewriteBase</code> is necessary
+ to avoid rewriting to http://example.com/opt/myapp-1.2.3/welcome.html
+ since the resource was not relative to the document root. This
+ misconfiguration would normally cause the server to look for an "opt"
+ directory under the document root.</p>
+<pre class="prettyprint lang-config">
+DocumentRoot /var/www/example.com
+Alias /myapp /opt/myapp-1.2.3
+&lt;Directory /opt/myapp-1.2.3&gt;
+ RewriteEngine On
+ RewriteBase /myapp/
+ RewriteRule ^index\.html$ welcome.html
+&lt;/Directory&gt;
+</pre>
</div>
@@ -340,7 +344,7 @@ RewriteRule ^index\.html$ newsite.html
<dt><code>REQUEST_SCHEME</code></dt>
- <dd>Will contain the scheme of the request (ususally
+ <dd>Will contain the scheme of the request (usually
"http" or "https"). This value can be influenced with
<code class="directive"><a href="../mod/core.html#servername">ServerName</a></code>.</dd>
@@ -617,10 +621,11 @@ RewriteRule ^index\.html$ newsite.html
to block unwanted hotlinking.
</p>
- <div class="example"><p><code>
+ <pre class="prettyprint lang-config">
RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"<br />
RewriteRule ^/images - [F]
- </code></p></div>
+ </pre>
+
</li>
<li>You can also set special flags for
@@ -646,12 +651,13 @@ RewriteRule ^index\.html$ newsite.html
Use this to combine rule conditions with a local OR
instead of the implicit AND. Typical example:
-<div class="example"><pre>
+<pre class="prettyprint lang-config">
RewriteCond %{REMOTE_HOST} ^host1 [OR]
RewriteCond %{REMOTE_HOST} ^host2 [OR]
RewriteCond %{REMOTE_HOST} ^host3
RewriteRule ...some special stuff for any of these hosts...
-</pre></div>
+</pre>
+
Without this flag you would have to write the condition/rule
pair three times.
@@ -676,7 +682,7 @@ RewriteRule ...some special stuff for any of these hosts...
``<code>User-Agent:</code>'' header of the request, you can
use the following: </p>
-<div class="example"><pre>
+<pre class="prettyprint lang-config">
RewriteCond %{HTTP_USER_AGENT} ^Mozilla
RewriteRule ^/$ /homepage.max.html [L]
@@ -684,7 +690,8 @@ RewriteCond %{HTTP_USER_AGENT} ^Lynx
RewriteRule ^/$ /homepage.min.html [L]
RewriteRule ^/$ /homepage.std.html [L]
-</pre></div>
+</pre>
+
<p>Explanation: If you use a browser which identifies itself
as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
@@ -774,16 +781,18 @@ Apache HTTP Server 2.0.41 and later</td></tr>
<p>For example, you might define a
<code class="directive">RewriteMap</code> as:</p>
- <div class="example"><p><code>
+ <pre class="prettyprint lang-config">
RewriteMap examplemap txt:/path/to/file/map.txt
- </code></p></div>
+ </pre>
+
<p>You would then be able to use this map in a
<code class="directive">RewriteRule</code> as follows:</p>
- <div class="example"><p><code>
+ <pre class="prettyprint lang-config">
RewriteRule ^/ex/(.*) ${examplemap:$1}
- </code></p></div>
+ </pre>
+
<p>The following combinations for <em>MapType</em> and
<em>MapSource</em> can be used:</p>
@@ -886,6 +895,35 @@ later</td></tr>
later.</p>
</dd>
+ <dt><code>AllowAnyURI</code></dt>
+ <dd>
+
+ <p>When <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
+ is used in <code>VirtualHost</code> or server context with
+ version 2.2.22 or later of httpd, <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>
+ will only process the rewrite rules if the request URI is a <a href="./directive-dict.html#Syntax">URL-path</a>. This avoids
+ some security issues where particular rules could allow
+ "surprising" pattern expansions (see <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3368">CVE-2011-3368</a>
+ and <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-4317">CVE-2011-4317</a>).
+ To lift the restriction on matching a URL-path, the
+ <code>AllowAnyURI</code> option can be enabled, and
+ <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> will apply the rule set to any
+ request URI string, regardless of whether that string matches
+ the URL-path grammar required by the HTTP specification.</p>
+
+ <div class="warning">
+ <h3>Security Warning</h3>
+
+ <p>Enabling this option will make the server vulnerable to
+ security issues if used with rewrite rules which are not
+ carefully authored. It is <strong>strongly recommended</strong>
+ that this option is not used. In particular, beware of input
+ strings containing the '<code>@</code>' character which could
+ change the interpretation of the transformed URI, as per the
+ above CVE names.</p>
+ </div>
+ </dd>
+
</dl>
@@ -909,10 +947,11 @@ later</td></tr>
<p><a id="patterns" name="patterns"><em>Pattern</em></a> is
a perl compatible <a id="regexp" name="regexp">regular
- expression</a>. On the first RewriteRule it is applied to the (%-decoded)
- <a href="./directive-dict.html#Syntax">URL-path</a> of the request;
- subsequent patterns are applied to the output of the last matched
- RewriteRule.</p>
+ expression</a>. On the first RewriteRule, it is matched against
+ the (%-decoded) <a href="./directive-dict.html#Syntax">URL-path</a> (or
+ <a href="./directive-dict.html#Syntax">file-path</a>, depending
+ on the context) of the request. Subsequent patterns are matched against the
+ output of the last matching RewriteRule.</p>
<div class="note"><h3><a id="what_is_matched" name="what_is_matched">What is matched?</a></h3>
<p>In <code class="directive"><a href="../mod/core.html#virtualhost">VirtualHost</a></code> context,
@@ -921,7 +960,7 @@ later</td></tr>
<p>In <code class="directive"><a href="../mod/core.html#directory">Directory</a></code> and htaccess context,
the <em>Pattern</em> will initially be matched against the
- <em>filesystem</em> path, after removing the prefix that lead the server
+ <em>filesystem</em> path, after removing the prefix that led the server
to the current <code class="directive">RewriteRule</code> (e.g. "app1/index.html"
or "index.html" depending on where the directives are defined).</p>
@@ -951,7 +990,7 @@ and automatically <em>added</em> after any relative (not starting with a
slash or protocol name) substitution encounters the end of a rule set.
See the <code class="directive"><a href="#rewritebase">RewriteBase</a></code>
directive for more information regarding what prefix will be added back to
-relative substitions.</li>
+relative substitutions.</li>
<li> If you wish to match against the full URL-path in a per-directory
(htaccess) RewriteRule, use the <code>%{REQUEST_URI}</code> variable in
@@ -1000,7 +1039,7 @@ cannot use <code>$N</code> in the substitution string!
to be delivered to the client. Substitutions are only
treated as a file-system path when the rule is configured in
server (virtualhost) context and the first component of the
- path in the substitution is exists in the file-system</dd>
+ path in the substitution exists in the file-system</dd>
<dt>URL-path</dt>
@@ -1037,7 +1076,7 @@ cannot use <code>$N</code> in the substitution string!
</dl>
- <p>In addition to plain text, the <em>Substition</em> string can include</p>
+ <p>In addition to plain text, the <em>Substitution</em> string can include</p>
<ol>
<li>back-references (<code>$N</code>) to the RewriteRule
@@ -1065,7 +1104,7 @@ cannot use <code>$N</code> in the substitution string!
<p>Rewrite rules are applied to the results of previous rewrite
rules, in the order in which they are defined
- in the config file. The URI or file path (see <a href="#what_is_matched">"What is matched?"</a>, above) is <strong>completely
+ in the config file. The URL-path or file-system path (see <a href="#what_is_matched">"What is matched?"</a>, above) is <strong>completely
replaced</strong> by the <em>Substitution</em> and the
rewriting process continues until all rules have been applied,
or it is explicitly terminated by an
@@ -1387,7 +1426,28 @@ redirection</td>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="../en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a> |
<a href="../fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
-</div><div id="footer">
+</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>
+<script type="text/javascript"><!--//--><![CDATA[//><!--
+var comments_shortname = 'httpd';
+var comments_identifier = 'http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html';
+(function(w, d) {
+ if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
+ d.write('<div id="comments_thread"><\/div>');
+ var s = d.createElement('script');
+ s.type = 'text/javascript';
+ s.async = true;
+ s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
+ (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
+ }
+ else {
+ d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
+ }
+})(window, document);
+//--><!]]></script></div><div id="footer">
<p class="apache">Copyright 2012 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="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>
+<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();
+}
+//--><!]]></script>
</body></html> \ No newline at end of file