avoid.html.en revision 181523b7d40e95e62d1b041846436ce1e7348e88
97a9a944b5887e91042b019776c41d5dd74557aferikabele<?xml version="1.0" encoding="ISO-8859-1"?>
97a9a944b5887e91042b019776c41d5dd74557aferikabele<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
97a9a944b5887e91042b019776c41d5dd74557aferikabele<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
8c81ebbdeed67059e7a1106d7c617543e901c3abyoshiki XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
8c81ebbdeed67059e7a1106d7c617543e901c3abyoshiki This file is generated from xml source: DO NOT EDIT
8c81ebbdeed67059e7a1106d7c617543e901c3abyoshiki XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd -->
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc<title>When not to use mod_rewrite - Apache HTTP Server</title>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<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" />
2e545ce2450a9953665f701bb05350f0d3f26275nd<script src="/style/scripts/prettify.js" type="text/javascript">
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen</script>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<body id="manual-page"><div id="page-header">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<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>
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen<p class="apache">Apache HTTP Server Version 2.5</p>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<img alt="" src="/images/feather.gif" /></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="path">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<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.5</a> &gt; <a href="./">Rewrite</a></div><div id="page-content"><div id="preamble"><h1>When not to use mod_rewrite</h1>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<div class="toplang">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<p><span>Available Languages: </span><a href="/en/rewrite/avoid.html" title="English">&nbsp;en&nbsp;</a></p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd<p>This document supplements the <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<a href="/mod/mod_rewrite.html">reference documentation</a>. It describes
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjungperhaps one of the most important concepts about mod_rewrite - namely,
3b3b7fc78d1f5bfc2769903375050048ff41ff26ndwhen to avoid using it.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<p>mod_rewrite should be considered a last resort, when other
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndalternatives are found wanting. Using it when there are simpler
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndalternatives leads to configurations which are confusing, fragile, and
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndhard to maintain. Understanding what other alternatives are available is
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nda very important step towards mod_rewrite mastery.</p>
8c81ebbdeed67059e7a1106d7c617543e901c3abyoshiki
8c81ebbdeed67059e7a1106d7c617543e901c3abyoshiki<p>Note that many of these examples won't work unchanged in your
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndparticular server configuration, so it's important that you understand
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndthem, rather than merely cutting and pasting the examples into your
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndconfiguration.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<p>The most common situation in which <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> is
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndthe right tool is when the very best solution requires access to the
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndserver configuration files, and you don't have that access. Some
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndconfiguration directives are only available in the server configuration
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndfile. So if you are in a hosting situation where you only have .htaccess
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndfiles to work with, you may need to resort to
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>.</p>
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#redirect">Simple Redirection</a></li>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<li><img alt="" src="/images/down.gif" /> <a href="#alias">URL Aliasing</a></li>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<li><img alt="" src="/images/down.gif" /> <a href="#vhosts">Virtual Hosting</a></li>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<li><img alt="" src="/images/down.gif" /> <a href="#proxy">Simple Proxying</a></li>
f61ec47ec494705bd2d02b5b6fe021e5c193f2c8noodl<li><img alt="" src="/images/down.gif" /> <a href="#setenv">Environment Variable Testing</a></li>
f61ec47ec494705bd2d02b5b6fe021e5c193f2c8noodl</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">Using RewriteMap</a></li><li><a href="advanced.html">Advanced techniques</a></li></ul></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="section">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<h2><a name="redirect" id="redirect">Simple Redirection</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<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
06ba4a61654b3763ad65f52283832ebf058fdf1cslivemeans to redirect one URL to another. This kind of simple redirection of
06ba4a61654b3763ad65f52283832ebf058fdf1csliveone URL, or a class of URLs, to somewhere else, should be accomplished
06ba4a61654b3763ad65f52283832ebf058fdf1csliveusing these directives rather than <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>. <code>RedirectMatch</code>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveallows you to include a regular expression in your redirection criteria,
06ba4a61654b3763ad65f52283832ebf058fdf1csliveproviding many of the benefits of using <code>RewriteRule</code>.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<p>A common use for <code>RewriteRule</code> is to redirect an entire
06ba4a61654b3763ad65f52283832ebf058fdf1csliveclass of URLs. For example, all URLs in the <code>/one</code> directory
06ba4a61654b3763ad65f52283832ebf058fdf1cslivemust be redirected to <code>http://one.example.com/</code>, or perhaps
06ba4a61654b3763ad65f52283832ebf058fdf1csliveall <code>http</code> requests must be redirected to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<code>https</code>.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<p>These situations are better handled by the <code>Redirect</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedirective. Remember that <code>Redirect</code> preserves path
06ba4a61654b3763ad65f52283832ebf058fdf1csliveinformation. That is to say, a redirect for a URL <code>/one</code> will
06ba4a61654b3763ad65f52283832ebf058fdf1cslivealso redirect all URLs under that, such as <code>/one/two.html</code>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveand <code>/one/three/four.html</code>.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<p>To redirect URLs under <code>/one</code> to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<code>http://one.example.com</code>, do the following:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<pre class="prettyprint lang-config">Redirect /one/ http://one.example.com/</pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<p>To redirect <code>http</code> URLs to <code>https</code>, do the
06ba4a61654b3763ad65f52283832ebf058fdf1cslivefollowing:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<pre class="prettyprint lang-config">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive&lt;VirtualHost *:80&gt;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ServerName www.example.com
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Redirect / https://www.example.com/
82178a3043043b8813c0d7288a06ca1b7d110d4atakashi&lt;/VirtualHost &gt;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive&lt;VirtualHost *:443&gt;
e1e8390280254f7f0580d701e583f670643d4f3fnilgun ServerName www.example.com
e1e8390280254f7f0580d701e583f670643d4f3fnilgun # ... SSL configuration goes here
e1e8390280254f7f0580d701e583f670643d4f3fnilgun&lt;/VirtualHost &gt;
e1e8390280254f7f0580d701e583f670643d4f3fnilgun</pre>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun
e1e8390280254f7f0580d701e583f670643d4f3fnilgun
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<p>The use of <code>RewriteRule</code> to perform this task may be
e1e8390280254f7f0580d701e583f670643d4f3fnilgunappropriate if there are other <code>RewriteRule</code> directives in
e1e8390280254f7f0580d701e583f670643d4f3fnilgunthe same scope. This is because, when there are <code>Redirect</code>
e1e8390280254f7f0580d701e583f670643d4f3fnilgunand <code>RewriteRule</code> directives in the same scope, the
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<code>RewriteRule</code> directives will run first, regardless of the
e1e8390280254f7f0580d701e583f670643d4f3fnilgunorder of appearance in the configuration file.</p>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<p>In the case of the <em>http-to-https</em> redirection, the use of
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<code>RewriteRule</code> would be appropriate if you don't have access
e1e8390280254f7f0580d701e583f670643d4f3fnilgunto the main server configuration file, and are obliged to perform this
e1e8390280254f7f0580d701e583f670643d4f3fnilguntask in a <code>.htaccess</code> file instead.</p>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun
e1e8390280254f7f0580d701e583f670643d4f3fnilgun</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<div class="section">
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<h2><a name="alias" id="alias">URL Aliasing</a></h2>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<p>The <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code> directive
e1e8390280254f7f0580d701e583f670643d4f3fnilgunprovides mapping from a URI to a directory - usually a directory outside
e1e8390280254f7f0580d701e583f670643d4f3fnilgunof your <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>. Although it
e1e8390280254f7f0580d701e583f670643d4f3fnilgunis possible to perform this mapping with <code>mod_rewrite</code>,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<code>Alias</code> is the preferred method, for reasons of simplicity
3a6531f1fd50efd78381e5800802a1449096781esliveand performance.</p>
3a6531f1fd50efd78381e5800802a1449096781eslive
3a6531f1fd50efd78381e5800802a1449096781eslive<div class="example"><h3>Using Alias</h3><p><code>
97a9a944b5887e91042b019776c41d5dd74557aferikabele<pre class="prettyprint lang-config">Alias /cats /var/www/virtualhosts/felines/htdocs</pre>
3a6531f1fd50efd78381e5800802a1449096781eslive
e1e8390280254f7f0580d701e583f670643d4f3fnilgun</code></p></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<p>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveThe use of <code>mod_rewrite</code> to perform this mapping may be
e1e8390280254f7f0580d701e583f670643d4f3fnilgunappropriate when you do not have access to the server configuration
e1e8390280254f7f0580d701e583f670643d4f3fnilgunfiles. Alias may only be used in server or virtualhost context, and not
06ba4a61654b3763ad65f52283832ebf058fdf1cslivein a <code>.htaccess</code> file.
4aa603e6448b99f9371397d439795c91a93637eand</p>
4aa603e6448b99f9371397d439795c91a93637eand
17ade6df5ec233536985eb1c130a906c725dd614humbedooh<p>Symbolic links would be another way to accomplish the same thing, if
06ba4a61654b3763ad65f52283832ebf058fdf1csliveyou have <code>Options FollowSymLinks</code> enabled on your
e1e8390280254f7f0580d701e583f670643d4f3fnilgunserver.</p>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<div class="section">
20f499565e77defe9dab24dd85c02f38a1175855nd<h2><a name="vhosts" id="vhosts">Virtual Hosting</a></h2>
17ade6df5ec233536985eb1c130a906c725dd614humbedooh<p>Although it is possible to handle <a href="vhosts.html">virtual hosts
06ba4a61654b3763ad65f52283832ebf058fdf1cslivewith mod_rewrite</a>, it is seldom the right way. Creating individual
e1e8390280254f7f0580d701e583f670643d4f3fnilgun&lt;VirtualHost&gt; blocks is almost always the right way to go. In the
e1e8390280254f7f0580d701e583f670643d4f3fnilgunevent that you have an enormous number of virtual hosts, consider using
e06675c51d084791089d79c3ac18aeae8dd465fcrbb<code class="module"><a href="/mod/mod_vhost_alias.html">mod_vhost_alias</a></code> to create these hosts automatically.</p>
20f499565e77defe9dab24dd85c02f38a1175855nd
17ade6df5ec233536985eb1c130a906c725dd614humbedooh<p>Third-party modules such as <a href="http://www.cri.ensmp.fr/~coelho/mod_macro/">mod_macro</a> are
e1e8390280254f7f0580d701e583f670643d4f3fnilgunalso useful for creating a large number of virtual hosts dynamically.</p>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<p>Using <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> for vitualhost creation may be
e1e8390280254f7f0580d701e583f670643d4f3fnilgunappropriate if you are using a hosting service that does not provide
e1e8390280254f7f0580d701e583f670643d4f3fnilgunyou access to the server configuration files, and you are therefore
e1e8390280254f7f0580d701e583f670643d4f3fnilgunrestricted to configuration using <code>.htaccess</code> files.</p>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<p>See the <a href="vhosts.html">virtual hosts with mod_rewrite</a>
2f46ce2a814d7f2b126dfb9f1b25fd64e2fbdc11rbowendocument for more details on how you might accomplish this if it still
e1e8390280254f7f0580d701e583f670643d4f3fnilgunseems like the right approach.</p>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun
e1e8390280254f7f0580d701e583f670643d4f3fnilgun</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<div class="section">
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<h2><a name="proxy" id="proxy">Simple Proxying</a></h2>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<p><code>RewriteRule</code> provides the <a href="flags.html#flag_p">[P]</a> flag to pass rewritten URIs through
25d005c58102474e06fb67d748273b161d7198d0pquerna<code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code>.</p>
a5a2e98043365d3f5a8bb3c3cdfc252a4f11bf02nd
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf<pre class="prettyprint lang-config">
a5a2e98043365d3f5a8bb3c3cdfc252a4f11bf02ndRewriteRule ^/?images(.*) http://imageserver.local/images$1 [P]
a5a2e98043365d3f5a8bb3c3cdfc252a4f11bf02nd</pre>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<p>However, in many cases, when there is no actual pattern matching
e1e8390280254f7f0580d701e583f670643d4f3fnilgunneeded, as in the example shown above, the <code class="directive"><a href="/mod/mod_proxy.html#proxypass">ProxyPass</a></code> directive is a better choice.
2f46ce2a814d7f2b126dfb9f1b25fd64e2fbdc11rbowenThe example here could be rendered as:</p>
e1e8390280254f7f0580d701e583f670643d4f3fnilgun
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<pre class="prettyprint lang-config">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndProxyPass /images/ http://imageserver.local/images/
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</pre>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd<p>Note that whether you use <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> or <code class="directive"><a href="/mod/mod_proxy.html#proxypass">ProxyPass</a></code>, you'll still need to use the
e1e8390280254f7f0580d701e583f670643d4f3fnilgun<code class="directive"><a href="/mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code> directive to
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjungcatch redirects issued from the back-end server:</p>
727872d18412fc021f03969b8641810d8896820bhumbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd<pre class="prettyprint lang-config">
727872d18412fc021f03969b8641810d8896820bhumbedoohProxyPassReverse /images/ http://imageserver.local/images/
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh</pre>
0d0ba3a410038e179b695446bb149cce6264e0abnd
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh
727872d18412fc021f03969b8641810d8896820bhumbedooh<p>You may need to use <code>RewriteRule</code> instead when there are
0d0ba3a410038e179b695446bb149cce6264e0abndother <code>RewriteRule</code>s in effect in the same scope, as a
0d0ba3a410038e179b695446bb149cce6264e0abnd<code>RewriteRule</code> will usually take effect before a
0d0ba3a410038e179b695446bb149cce6264e0abnd<code>ProxyPass</code>, and so may preempt what you're trying to
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedoohaccomplish.</p>
0d0ba3a410038e179b695446bb149cce6264e0abnd
0d0ba3a410038e179b695446bb149cce6264e0abnd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0d0ba3a410038e179b695446bb149cce6264e0abnd<div class="section">
727872d18412fc021f03969b8641810d8896820bhumbedooh<h2><a name="setenv" id="setenv">Environment Variable Testing</a></h2>
0d0ba3a410038e179b695446bb149cce6264e0abnd
0d0ba3a410038e179b695446bb149cce6264e0abnd<p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> is frequently used to take a particular
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedoohaction based on the presence or absence of a particular environment
205f749042ed530040a4f0080dbcb47ceae8a374rjungvariable or request header. This can be done more efficiently using the
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen<code class="directive"><a href="/mod/core.html#if">&lt;If&gt;</a></code>.</p>
0d0ba3a410038e179b695446bb149cce6264e0abnd
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd<p>Consider, for example, the common scenario where
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd<code class="directive">RewriteRule</code> is used to enforce a canonical
7fec19672a491661b2fe4b29f685bc7f4efa64d4ndhostname, such as <code>www.example.com</code> instead of
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<code>example.com</code>. This can be done using the <code class="directive"><a href="/mod/core.html#if">&lt;If&gt;</a></code> directive, as shown here:</p>
<pre class="prettyprint lang-config">
&lt;If "$req{Host} != 'www.example.com'"&gt;
RedirectMatch (.*) http://www.example.com$1
&lt;/If&gt;
</pre>
<p>This technique can be used to take actions based on any request
header, response header, or environment variable, replacing
<code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> in many common scenarios.</p>
<p>See especially the <a href="/expr.html">expression evaluation
documentation</a> for a overview of what types of expressions you can
use in &lt;If&gt; sections, and in certain other directives.</p>
</div></div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="/en/rewrite/avoid.html" title="English">&nbsp;en&nbsp;</a></p>
</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><script type="text/javascript">
if (typeof(prettyPrint) !== undefined) {
prettyPrint();
}
</script>
</body></html>