avoid.html.en revision cde7900bb5b14f5bd981ad98b0215c85b915bef7
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This file is generated from xml source: DO NOT EDIT
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-->
<title>When not to use 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" />
<body id="manual-page"><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="apache">Apache HTTP Server Version 2.3</p>
<div id="path">
<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.3</a> > <a href="./">Rewrite</a></div><div id="page-content"><div id="preamble"><h1>When not to use mod_rewrite</h1>
<div class="toplang">
<p><span>Available Languages: </span><a href="/en/rewrite/avoid.html" title="English"> en </a></p>
</div>
<p>This document supplements the <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
perhaps one of the most important concepts about mod_rewrite - namely,
when to avoid using it.</p>
<p>mod_rewrite should be considered a last resort, when other
alternatives are found wanting. Using it when there are simpler
alternatives leads to configurations which are confusing, fragile, and
hard to maintain. Understanding what other alternatives are available is
a very important step towards mod_rewrite mastery.</p>
<p>Note that many of these examples won't work unchanged in your
particular server configuration, so it's important that you understand
them, rather than merely cutting and pasting the examples into your
configuration.</p>
<div class="warning">This document is a work in progress.</div>
</div>
<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#redirect">Simple Redirection</a></li>
</ul><h3>See also</h3><ul class="seealso"><li><a href="/mod/mod_rewrite.html">Module documentation</a></li><li><a href="intro.html">mod_rewrite introduction</a></li><li><a href="remapping.html">Redirection and remapping</a></li><li><a href="access.html">Controlling access</a></li><li><a href="vhosts.html">Virtual hosts</a></li><li><a href="proxy.html">Proxying</a></li><li><a href="rewritemap.html">RewriteMap</a></li><li><a href="advanced.html">Advanced techniques and tricks</a></li></ul></div>
<div class="section">
<h2><a name="redirect" id="redirect">Simple Redirection</a></h2>
<p><code class="module"><a href="/mod/mod_alias.html">mod_alias</a></code> provides the <code class="directive"><a href="/mod/mod_alias.html#redirect">Redirect</a></code> and <code class="directive"><a href="/mod/mod_alias.html#redirectmatch">RedirectMatch</a></code> directives, which provide a
means 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 <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>. <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
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
<p>To redirect URLs under <code>/one</code> to
<div class="example"><p><code>
Redirect /one/ http://one.example.com/
</code></p></div>
<p>To redirect <code>http</code> URLs to <code>https</code>, do the
following:</p>
<div class="example"><p><code>
<VirtualHost *:80>
ServerName www.example.com<br />
Redirect / https://www.example.com/<br />
</VirtualHost >
<br />
<VirtualHost *:443>
ServerName www.example.com<br />
<br />
# ... SSL configuration goes here<br />
</VirtualHost >
</code></p></div>
<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>
<div class="section">
<h2><a name="alias" id="alias">URL Aliasing</a></h2>
provides mapping from a URI to a directory - usually a directory outside
of your <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>. Although it
is possible to perform this mappint with <code>mod_rewrite</code>,
<code>Alias</code> is the preferred method, for reasons of simplicity
and performance.</p>
<div class="example"><h3>Using Alias</h3><p><code>
</code></p></div>
<p>
The use of <code>mod_rewrite</code> to perform this mapping may be
appropriate when you do not have access to the server configuration
files. Alias may only be used in server or virtualhost context, and not
in a <code>.htaccess</code> file.
</p>
<p>Symbolic links would be another way to accomplish the same thing, if
you have <code>Options FollowSymLinks</code> enabled on your
server.</p>
<div class="section">
<h2><a name="vhosts" id="vhosts">Virtual Hosting</a></h2>
with mod_rewrite</a>, it is </p>
<div class="section">
<h2><a name="proxy" id="proxy">Simple Proxying</a></h2>
<p>ProxyPass</p>
<div class="section">
<h2><a name="setenv" id="setenv">Environment Variable Testing</a></h2>
<div class="note">Parts of this section are applicable only to Apache HTTP
Server 2.3 and later.</div>
<p>Using SetEnvIf and <If> (2.3 and later.)</p>
</div></div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="/en/rewrite/avoid.html" title="English"> en </a></p>
</div><div id="footer">
<p class="apache">Copyright 2010 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>
</body></html>