avoid.xml revision 9e4fd920b1e57cb1a7113cde0959b9ff1689d1df
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<?xml version="1.0" encoding="UTF-8" ?>
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<!DOCTYPE manualpage SYSTEM "/style/manualpage.dtd">
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
6896b3498e144d33f374efe93e6bab2669af535fnd<!-- $LastChangedRevision$ -->
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<!--
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen Licensed to the Apache Software Foundation (ASF) under one or more
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen contributor license agreements. See the NOTICE file distributed with
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen this work for additional information regarding copyright ownership.
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen The ASF licenses this file to You under the Apache License, Version 2.0
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen (the "License"); you may not use this file except in compliance with
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen the License. You may obtain a copy of the License at
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen http://www.apache.org/licenses/LICENSE-2.0
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen Unless required by applicable law or agreed to in writing, software
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen distributed under the License is distributed on an "AS IS" BASIS,
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen See the License for the specific language governing permissions and
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen limitations under the License.
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen-->
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<manualpage metafile="avoid.xml.meta">
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen <parentdocument href="./">Rewrite</parentdocument>
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<title>When not to use mod_rewrite</title>
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<summary>
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<p>This document supplements the <module>mod_rewrite</module>
2bb0656f94af82b1ff5e3e77a99b4427c52e4953rbowen<a href="/mod/mod_rewrite.html">reference documentation</a>. It describes
4a1711ab536d965e63d7be80e29f912287fe70b2rbowenperhaps one of the most important concepts about mod_rewrite - namely,
4a1711ab536d965e63d7be80e29f912287fe70b2rbowenwhen to avoid using it.</p>
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<p>mod_rewrite should be considered a last resort, when other
4a1711ab536d965e63d7be80e29f912287fe70b2rbowenalternatives are found wanting. Using it when there are simpler
4a1711ab536d965e63d7be80e29f912287fe70b2rbowenalternatives leads to configurations which are confusing, fragile, and
4a1711ab536d965e63d7be80e29f912287fe70b2rbowenhard to maintain. Understanding what other alternatives are available is
4a1711ab536d965e63d7be80e29f912287fe70b2rbowena very important step towards mod_rewrite mastery.</p>
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<p>Note that many of these examples won't work unchanged in your
4a1711ab536d965e63d7be80e29f912287fe70b2rbowenparticular server configuration, so it's important that you understand
4a1711ab536d965e63d7be80e29f912287fe70b2rbowenthem, rather than merely cutting and pasting the examples into your
4a1711ab536d965e63d7be80e29f912287fe70b2rbowenconfiguration.</p>
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<note type="warning">This document is a work in progress.</note>
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen</summary>
8b79a240383bcecf28b75d4803683a7d101d2713rbowen<seealso><a href="/mod/mod_rewrite.html">Module documentation</a></seealso>
8b79a240383bcecf28b75d4803683a7d101d2713rbowen<seealso><a href="intro.html">mod_rewrite introduction</a></seealso>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<seealso><a href="remapping.html">Redirection and remapping</a></seealso>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<seealso><a href="access.html">Controlling access</a></seealso>
8b79a240383bcecf28b75d4803683a7d101d2713rbowen<seealso><a href="vhosts.html">Virtual hosts</a></seealso>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<seealso><a href="proxy.html">Proxying</a></seealso>
4a1711ab536d965e63d7be80e29f912287fe70b2rbowen<seealso><a href="advanced.html">Advanced techniques and tricks</a></seealso>
5bfbe6eab78fa063a7de24cea3262293fcd5499erbowen<!--<seealso><a href="avoid.html">When not to use mod_rewrite</a></seealso>-->
5bfbe6eab78fa063a7de24cea3262293fcd5499erbowen
5bfbe6eab78fa063a7de24cea3262293fcd5499erbowen<section id="redirect">
5bfbe6eab78fa063a7de24cea3262293fcd5499erbowen<title>Simple Redirection</title>
5bfbe6eab78fa063a7de24cea3262293fcd5499erbowen
5bfbe6eab78fa063a7de24cea3262293fcd5499erbowen<p><module>mod_alias</module> provides the <directive
5bfbe6eab78fa063a7de24cea3262293fcd5499erbowenmodule="mod_alias">Redirect</directive> and <directive
4a1711ab536d965e63d7be80e29f912287fe70b2rbowenmodule="mod_alias">RedirectMatch</directive> directives, which provide a
4a1711ab536d965e63d7be80e29f912287fe70b2rbowenmeans to redirect one URL to another. This kind of simple redirection of
one URL, or a class of URLs, to somewhere else, should be accomplished
using these directives rather than <directive
module="mod_rewrite">RewriteRule</directive>. <code>RedirectMatch</code>
allows you to include a regular expression in your redirection criteria,
providing many of the benefits of using <code>RewriteRule</code>.</p>
<p>A common use for <code>RewriteRule</code> is to redirect an entire
class of URLs. For example, all URLs in the <code>/one</code> directory
must be redirected to <code>http://one.example.com/</code>, or perhaps
all <code>http</code> requests must be redirected to
<code>https</code>.</p>
<p>These situations are better handled by the <code>Redirect</code>
directive. Remember that <code>Redirect</code> preserves path
information. That is to say, a redirect for a URL <code>/one</code> will
also redirect all URLs under that, such as <code>/one/two.html</code>
and <code>/one/three/four.html</code>.</p>
<p>To redirect URLs under <code>/one</code> to
<code>http://one.example.com</code>, do the following:</p>
<example>
Redirect /one/ http://one.example.com/
</example>
<p>To redirect <code>http</code> URLs to <code>https</code>, do the
following:</p>
<example>
&lt;VirtualHost *:80&gt;
ServerName www.example.com<br />
Redirect / https://www.example.com/<br />
&lt;/VirtualHost &gt;
<br />
&lt;VirtualHost *:443&gt;
ServerName www.example.com<br />
<br />
# ... SSL configuration goes here<br />
&lt;/VirtualHost &gt;
</example>
<p>The use of <code>RewriteRule</code> to perform this task may be
appropriate if there are other <code>RewriteRule</code> directives in
the same scope. This is because, when there are <code>Redirect</code>
and <code>RewriteRule</code> directives in the same scope, the
<code>RewriteRule</code> directives will run first, regardless of the
order of appearance in the configuration file.</p>
<p>In the case of the <em>http-to-https</em> redirection, the use of
<code>RewriteRule</code> would be appropriate if you don't have access
to the main server configuration file, and are obliged to perform this
task in a <code>.htaccess</code> file instead.</p>
</section>
<section id="alias"><title>URL Aliasing</title>
<p>Using Alias</p>
</section>
<section id="vhosts"><title>Virtual Hosting</title>
<p>Virtual Hosts</p>
</section>
<section id="proxy"><title>Simple Proxying</title>
<p>ProxyPass</p>
</section>
<section id="setenv"><title>Environment Variable Testing</title>
<note type="note">Parts of this section are applicable only to Apache HTTP
Server 2.3 and later.</note>
<p>Using SetEnvIf and &lt;If&gt; (2.3 and later.)</p>
</section>
</manualpage>