flags.html.en revision c8ae9f6fe147ca611e49bddebf0876d2987adfae
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz<?xml version="1.0" encoding="ISO-8859-1"?>
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd This file is generated from xml source: DO NOT EDIT
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb -->
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd<title>RewriteRule Flags - Apache HTTP Server</title>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd<body id="manual-page"><div id="page-header">
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd<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>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<p class="apache">Apache HTTP Server Version 2.5</p>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<img alt="" src="/images/feather.gif" /></div>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<div id="path">
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<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>RewriteRule Flags</h1>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<div class="toplang">
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<p><span>Available Languages: </span><a href="/en/rewrite/flags.html" title="English">&nbsp;en&nbsp;</a> |
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<a href="/fr/rewrite/flags.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb</div>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<p>This document discusses the flags which are available to the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> directive,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbproviding detailed explanations and examples.</p>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb</div>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#introduction">Introduction</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_b">B (escape backreferences)</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_c">C|chain</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_co">CO|cookie</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_dpi">DPI|discardpath</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_e">E|env</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_end">END</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_f">F|forbidden</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_g">G|gone</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_h">H|handler</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_l">L|last</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_n">N|next</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_nc">NC|nocase</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_ne">NE|noescape</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_ns">NS|nosubreq</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_p">P|proxy</a></li>
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames<li><img alt="" src="/images/down.gif" /> <a href="#flag_pt">PT|passthrough</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_qsa">QSA|qsappend</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_qsd">QSD|qsdiscard</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_r">R|redirect</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_s">S|skip</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<li><img alt="" src="/images/down.gif" /> <a href="#flag_t">T|type</a></li>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb</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><li><a href="avoid.html">When not to use mod_rewrite</a></li></ul></div>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<div class="section">
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz<h2><a name="introduction" id="introduction">Introduction</a></h2>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz<p>A <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> can have
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzits behavior modified by one or more flags. Flags are included in
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzsquare brackets at the end of the rule, and multiple flags are separated
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzby commas.</p>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz<div class="example"><p><code>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzRewriteRule pattern target [Flag1,Flag2,Flag3]
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz</code></p></div>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<p>The flags all have a short form, such as <code>CO</code>, as well as
b38846b15c8891c6dec44dcc4f96ca40721bf663rbba longer form, such as <code>cookie</code>. Some flags take one or more
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbarguments. Flags are not case sensitive.</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe<p>Each flag (with a few exceptions)
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerhas a long and short form. While it is most common to use
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbthe short form, it is recommended that you familiarize yourself with the
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerlong form, so that you remember what each flag is supposed to do.</p>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>Flags that alter metadata associated with the request (T=, H=, E=)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbhave no affect in per-directory and htaccess context, when a substitution
4f9c22c4f27571d54197be9674e1fc0d528192aestriker(other than '-') is performed during the same round of rewrite processing.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<p>Presented here are each of the available flags, along with an example
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerof how you might use them.</p>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<div class="section">
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<h2><a name="flag_b" id="flag_b">B (escape backreferences)</a></h2>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<p>The [B] flag instructs <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> to escape non-alphanumeric
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowecharacters before applying the transformation.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe</p>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<p><code>mod_rewrite</code> has to unescape URLs before mapping them,
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawickso backreferences will be unescaped at the time they are applied.
c2cf53a40a9814eb91db2cdf820f97d943f21628coarUsing the B flag, non-alphanumeric characters in backreferences
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowewill be escaped. For example, consider the rule:</p>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar<div class="example"><p><code>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewroweRewriteRule ^search/(.*)$ /search.php?term=$1
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar</code></p></div>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<p>Given a search term of 'x &amp; y/z', a browser will encode it as
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe'x%20%26%20y%2Fz', making the request 'search/x%20%26%20y%2Fz'. Without the B
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewroweflag, this rewrite rule will map to 'search.php?term=x &amp; y/z', which
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewroweisn't a valid URL, and so would be encoded as
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<code>search.php?term=x%20&amp;y%2Fz=</code>, which is not what was intended.</p>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<p>With the B flag set on this same rule, the parameters are re-encoded
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowebefore being passed on to the output URL, resulting in a correct mapping to
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames<code>/search.php?term=x%20%26%20y%2Fz</code>.</p>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<p>Note that you may also need to set <code class="directive"><a href="/mod/core.html#allowencodedslashes">AllowEncodedSlashes</a></code> to <code>On</code> to get this
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewroweparticular example to work, as httpd does not allow encoded slashes in URLs, and
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowereturns a 404 if it sees one.</p>
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar<p>This escaping is particularly necessary in a proxy situation,
8419e6f8bff1a3617933f3ba760d2bdec7442f44coarwhen the backend may break if presented with an unescaped URL.</p>
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar<div class="section">
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar<h2><a name="flag_c" id="flag_c">C|chain</a></h2>
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar<p>The [C] or [chain] flag indicates that the <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> is chained to the next
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzrule. That is, if the rule matches, then it is processed as usual and
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coarcontrol moves on to the next rule. However, if it does not match, then
8419e6f8bff1a3617933f3ba760d2bdec7442f44coarthe next rule, and any other rules that are chained together, will be
8419e6f8bff1a3617933f3ba760d2bdec7442f44coarskipped.</p>
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar<div class="section">
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar<h2><a name="flag_co" id="flag_co">CO|cookie</a></h2>
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar<p>The [CO], or [cookie] flag, allows you to set a cookie when a
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzparticular <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzmatches. The argument consists of three required fields and four optional
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowefields.</p>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<p>The full syntax for the flag, including all attributes, is as
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowefollows:</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<div class="example"><p><code>
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames[CO=NAME:VALUE:DOMAIN:lifetime:path:secure:httponly]
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe</code></p></div>
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<p>You must declare a name, a value, and a domain for the cookie to be set.</p>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<dl>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<dt>Domain</dt>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<dd>The domain for which you want the cookie to be valid. This may be a
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowehostname, such as <code>www.example.com</code>, or it may be a domain,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowesuch as <code>.example.com</code>. It must be at least two parts
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewroweseparated by a dot. That is, it may not be merely <code>.com</code> or
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<code>.net</code>. Cookies of that kind are forbidden by the cookie
4f9c22c4f27571d54197be9674e1fc0d528192aestrikersecurity model.</dd>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe</dl>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<p>You may optionally also set the following values:</p>
c2cf53a40a9814eb91db2cdf820f97d943f21628coar
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<dl>
4775dfc34c90fada8c7c4d6a57ed8a3114d55c2dtrawick<dt>Lifetime</dt>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<dd>The time for which the cookie will persist, in minutes.</dd>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<dd>A value of 0 indicates that the cookie will persist only for the
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowecurrent browser session. This is the default value if none is
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowespecified.</dd>
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<dt>Path</dt>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<dd>The path, on the current website, for which the cookie is valid,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowesuch as <code>/customers/</code> or <code>/files/download/</code>.</dd>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<dd>By default, this is set to <code>/</code> - that is, the entire
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowewebsite.</dd>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<dt>Secure</dt>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<dd>If set to <code>secure</code>, <code>true</code>, or <code>1</code>,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowethe cookie will only be permitted to be translated via secure (https)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewroweconnections.</dd>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<dt>httponly</dt>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<dd>If set to <code>HttpOnly</code>, <code>true</code>, or
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<code>1</code>, the cookie will have the <code>HttpOnly</code> flag set,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowewhich means that the cookie will be inaccessible to JavaScript code on
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowebrowsers that support this feature.</dd>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe</dl>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<p>Several examples are offered here:</p>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<div class="example"><p><code>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wroweRewriteEngine On<br />
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerRewriteRule ^/index\.html - [CO=frontdoor:yes:.example.com:1440:/]
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe</code></p></div>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<p>In the example give, the rule doesn't rewrite the request.
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wroweThe "-" rewrite target tells mod_rewrite to pass the request
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarthrough unchanged. Instead, it sets a cookie
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowecalled 'frontdoor' to a value of 'yes'. The cookie is valid for any host
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowein the <code>.example.com</code> domain. It will be set to expire in 1440
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wroweminutes (24 hours) and will be returned for all URIs.</p>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<div class="section">
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<h2><a name="flag_dpi" id="flag_dpi">DPI|discardpath</a></h2>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<p>The DPI flag causes the PATH_INFO portion of the rewritten URI to be
c2cf53a40a9814eb91db2cdf820f97d943f21628coardiscarded.</p>
c2cf53a40a9814eb91db2cdf820f97d943f21628coar<p>This flag is available in version 2.2.12 and later.</p>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<p>In per-directory context, the URI each <code class="directive">RewriteRule</code>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzcompares against is the concatenation of the current values of the URI
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzand PATH_INFO.</p>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<p>The current URI can be the initial URI as requested by the client, the
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerresult of a previous round of mod_rewrite processing, or the result of
c2cf53a40a9814eb91db2cdf820f97d943f21628coara prior rule in the current round of mod_rewrite processing.</p>
c2cf53a40a9814eb91db2cdf820f97d943f21628coar
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<p>In contrast, the PATH_INFO that is appended to the URI before each
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzrule reflects only the value of PATH_INFO before this round of
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzmod_rewrite processing. As a consequence, if large portions
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzof the URI are matched and copied into a substitution in multiple
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<code class="directive">RewriteRule</code> directives, without regard for
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowewhich parts of the URI came from the current PATH_INFO, the final
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wroweURI may have multiple copies of PATH_INFO appended to it.</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe<p>Use this flag on any substitution where the PATH_INFO that resulted
08ab23ee4e41ac8587da5a3bb8d4e9c49523b0b8ndfrom the previous mapping of this request to the filesystem is not of
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wroweinterest. This flag permanently forgets the PATH_INFO established
08ab23ee4e41ac8587da5a3bb8d4e9c49523b0b8ndbefore this round of mod_rewrite processing began. PATH_INFO will
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowenot be recalculated until the current round of mod_rewrite processing
4f9c22c4f27571d54197be9674e1fc0d528192aestrikercompletes. Subsequent rules during this round of processing will see
c2cf53a40a9814eb91db2cdf820f97d943f21628coaronly the direct result of substitutions, without any PATH_INFO
c2cf53a40a9814eb91db2cdf820f97d943f21628coarappended.</p>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz<div class="section">
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz<h2><a name="flag_e" id="flag_e">E|env</a></h2>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz<p>With the [E], or [env] flag, you can set the value of an environment
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowevariable. Note that some environment variables may be set after the rule
4f9c22c4f27571d54197be9674e1fc0d528192aestrikeris run, thus unsetting what you have set. See <a href="/env.html">the
c2cf53a40a9814eb91db2cdf820f97d943f21628coarEnvironment Variables document</a> for more details on how Environment
c2cf53a40a9814eb91db2cdf820f97d943f21628coarvariables work.</p>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz<p>The full syntax for this flag is:</p>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz<div class="example"><p><code>
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe[E=VAR:VAL]
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe[E=!VAR]
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe</code></p></div>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<p><code>VAL</code> may contain backreferences (<code>$N</code> or
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<code>%N</code>) which will be expanded.</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<p>Using the short form</p>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<div class="example"><p><code>
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz[E=VAR]
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe</code></p></div>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<p>you can set the environment variable named <code>VAR</code> to an
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewroweempty value.</p>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<p>The form</p>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe<div class="example"><p><code>
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe[E=!VAR]
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe</code></p></div>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<p>allows to unset a previously set environment variable named
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<code>VAR</code>.</p>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<p>Environment variables can then be used in a variety of
4f9c22c4f27571d54197be9674e1fc0d528192aestrikercontexts, including CGI programs, other RewriteRule directives, or
cc9582e53aead2a044077c4a92f3dfc3605590b3wroweCustomLog directives.</p>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<p>The following example sets an environment variable called 'image' to a
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowevalue of '1' if the requested URI is an image file. Then, that
0540a0b469147b52e858587270dba31c2aaa9e09wroweenvironment variable is used to exclude those requests from the access
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowelog.</p>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<div class="example"><p><code>
cc9582e53aead2a044077c4a92f3dfc3605590b3wroweRewriteRule \.(png|gif|jpg) - [E=image:1]<br />
cc9582e53aead2a044077c4a92f3dfc3605590b3wroweCustomLog logs/access_log combined env=!image
4f9c22c4f27571d54197be9674e1fc0d528192aestriker</code></p></div>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>Note that this same effect can be obtained using <code class="directive"><a href="/mod/mod_setenvif.html#setenvif">SetEnvIf</a></code>. This technique is offered as
4f9c22c4f27571d54197be9674e1fc0d528192aestrikeran example, not as a recommendation.</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<div class="section">
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<h2><a name="flag_end" id="flag_end">END</a></h2>
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp<p>Using the [END] flag terminates not only the current round ot rewrite
cc9582e53aead2a044077c4a92f3dfc3605590b3wroweprocessing (like [L]) but also prevents any subsequent rewrite
cc9582e53aead2a044077c4a92f3dfc3605590b3wroweprocessing from occurring in per-directory (htaccess) context.</p>
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<p>This does not apply to new requests resulting from external
cc9582e53aead2a044077c4a92f3dfc3605590b3wroweredirects.</p>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<div class="section">
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<h2><a name="flag_f" id="flag_f">F|forbidden</a></h2>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<p>Using the [F] flag causes the server to return a 403 Forbidden status
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowecode to the client. While the same behavior can be accomplished using
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianpthe <code class="directive"><a href="/mod/mod_access.html#deny">Deny</a></code> directive, this
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianpallows more flexibility in assigning a Forbidden status.</p>
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp<p>The following rule will forbid <code>.exe</code> files from being
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerdownloaded from your server.</p>
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp<div class="example"><p><code>
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerRewriteRule \.exe - [F]
4f9c22c4f27571d54197be9674e1fc0d528192aestriker</code></p></div>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>This example uses the "-" syntax for the rewrite target, which means
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerthat the requested URI is not modified. There's no reason to rewrite to
4f9c22c4f27571d54197be9674e1fc0d528192aestrikeranother URI, if you're going to forbid the request.</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp<p>When using [F], an [L] is implied - that is, the response is returned
7a2edaa0193cbb0d79a65a8461a609a9402aea49brianpimmediately, and no further rules are evaluated.</p>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<div class="section">
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<h2><a name="flag_g" id="flag_g">G|gone</a></h2>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<p>The [G] flag forces the server to return a 410 Gone status with the
cc9582e53aead2a044077c4a92f3dfc3605590b3wroweresponse. This indicates that a resource used to be available, but is no
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerlonger available.</p>
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<p>As with the [F] flag, you will typically use the "-" syntax for the
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowerewrite target when using the [G] flag:</p>
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe<div class="example"><p><code>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbRewriteRule oldproduct - [G,NC]
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb</code></p></div>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<p>When using [G], an [L] is implied - that is, the response is returned
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbimmediately, and no further rules are evaluated.</p>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<div class="section">
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<h2><a name="flag_h" id="flag_h">H|handler</a></h2>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<p>Forces the resulting request to be handled with the specified
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbhandler. For example, one might use this to force all files without a
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbfile extension to be parsed by the php handler:</p>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb<div class="example"><p><code>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbRewriteRule !\. - [H=application/x-httpd-php]
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb</code></p></div>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<p>
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerThe regular expression above - <code>!\.</code> - will match any request
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowethat does not contain the literal <code>.</code> character.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe</p>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<p>This can be also used to force the handler based on some conditions.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwroweFor example, the following snippet used in per-server context allows
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<code>.php</code> files to be <em>displayed</em> by <code>mod_php</code>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwroweif they are requested with the <code>.phps</code> extension:</p>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<div class="example"><p><code>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwroweRewriteRule ^(/source/.+\.php)s$ $1 [H=application/x-httpd-php-source]
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe</code></p></div>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<p>The regular expression above - <code>^(/source/.+\.php)s$</code> - will
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowematch any request that starts with <code>/source/</code> followed by 1 or
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowen characters followed by <code>.phps</code> literally. The backreference
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz$1 referrers to the captured match within parenthesis of the regular
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwroweexpression.</p>
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<div class="section">
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar<h2><a name="flag_l" id="flag_l">L|last</a></h2>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<p>The [L] flag causes <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> to stop processing
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantzthe rule set. In most contexts, this means that if the rule matches, no
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantzfurther rules will be processed. This corresponds to the
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz<code>last</code> command in Perl, or the <code>break</code> command in
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwroweC. Use this flag to indicate that the current rule should be applied
659ad814f714e556bdd03e1d771cba156baab92ewroweimmediately without considering further rules.</p>
659ad814f714e556bdd03e1d771cba156baab92ewrowe
659ad814f714e556bdd03e1d771cba156baab92ewrowe<p>If you are using <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> in either
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<code>.htaccess</code> files or in
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar<code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code> sections,
11fb2f3611e6ff9a541e10b13e3108934f828141gregamesit is important to have some understanding of how the rules are
11fb2f3611e6ff9a541e10b13e3108934f828141gregamesprocessed. The simplified form of this is that once the rules have been
11fb2f3611e6ff9a541e10b13e3108934f828141gregamesprocessed, the rewritten request is handed back to the URL parsing
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantzengine to do what it may with it. It is possible that as the rewritten
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantzrequest is handled, the <code>.htaccess</code> file or
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz<code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code> section
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantzmay be encountered again, and thus the ruleset may be run again from the
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerstart. Most commonly this will happen if one of the rules causes a
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwroweredirect - either internal or external - causing the request process to
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestart over.</p>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>It is therefore important, if you are using <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> directives in one of these
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowecontexts, that you take explicit steps to avoid rules looping, and not
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowecount solely on the [L] flag to terminate execution of a series of
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowerules, as shown below.</p>
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick<p> An alternative flag, [END], can be used to terminate not only the
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawickcurrent round of rewrite processing but prevent any subsequent
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarrewrite processing from occuring in per-directory (htaccess)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowecontext. This does not apply to new requests resulting from external
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarredirects.</p>
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<p>The example given here will rewrite any request to
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<code>index.php</code>, giving the original request as a query string
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerargument to <code>index.php</code>, however, the <code class="directive"><a href="/mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> ensures that if the request
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwroweis already for <code>index.php</code>, the <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> will be skipped.</p>
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<div class="example"><p><code>
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawickRewriteBase /<br />
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwroweRewriteCond %{REQUEST_URI} !=/index.php<br />
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarRewriteRule ^(.*) /index.php?req=$1 [L,PT]
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe</code></p></div>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<div class="section">
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz<h2><a name="flag_n" id="flag_n">N|next</a></h2>
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz<p>
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantzThe [N] flag causes the ruleset to start over again from the top, using
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantzthe result of the ruleset so far as a starting point. Use
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerwith extreme caution, as it may result in loop.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe</p>
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe<p>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbThe [Next] flag could be used, for example, if you wished to replace a
8aefbd756763807188d2e3ce336a8680e4893066wrowecertain string or letter repeatedly in a request. The example shown here
700b96db75e7cfadb5219978c1735b710d583763wrowewill replace A with B everywhere in a request, and will continue doing
700b96db75e7cfadb5219978c1735b710d583763wroweso until there are no more As to be replaced.
700b96db75e7cfadb5219978c1735b710d583763wrowe</p>
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe<div class="example"><p><code>
700b96db75e7cfadb5219978c1735b710d583763wroweRewriteRule (.*)A(.*) $1B$2 [N]
700b96db75e7cfadb5219978c1735b710d583763wrowe</code></p></div>
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe<p>You can think of this as a <code>while</code> loop: While this
700b96db75e7cfadb5219978c1735b710d583763wrowepattern still matches (i.e., while the URI still contains an
700b96db75e7cfadb5219978c1735b710d583763wrowe<code>A</code>), perform this substitution (i.e., replace the
700b96db75e7cfadb5219978c1735b710d583763wrowe<code>A</code> with a <code>B</code>).</p>
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
700b96db75e7cfadb5219978c1735b710d583763wrowe<div class="section">
700b96db75e7cfadb5219978c1735b710d583763wrowe<h2><a name="flag_nc" id="flag_nc">NC|nocase</a></h2>
103a93c625bcde1a6a7a5155b64dcda36f612180pquerna<p>Use of the [NC] flag causes the <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> to be matched in a
700b96db75e7cfadb5219978c1735b710d583763wrowecase-insensitive manner. That is, it doesn't care whether letters appear
700b96db75e7cfadb5219978c1735b710d583763wroweas upper-case or lower-case in the matched URI.</p>
6964758306167dd898baedd21048bd1515dd9d30trawick
700b96db75e7cfadb5219978c1735b710d583763wrowe<p>In the example below, any request for an image file will be proxied
700b96db75e7cfadb5219978c1735b710d583763wroweto your dedicated image server. The match is case-insensitive, so that
700b96db75e7cfadb5219978c1735b710d583763wrowe<code>.jpg</code> and <code>.JPG</code> files are both acceptable, for
700b96db75e7cfadb5219978c1735b710d583763wroweexample.</p>
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe<div class="example"><p><code>
700b96db75e7cfadb5219978c1735b710d583763wroweRewriteRule (.*\.(jpg|gif|png))$ http://images.example.com$1 [P,NC]
700b96db75e7cfadb5219978c1735b710d583763wrowe</code></p></div>
700b96db75e7cfadb5219978c1735b710d583763wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
700b96db75e7cfadb5219978c1735b710d583763wrowe<div class="section">
700b96db75e7cfadb5219978c1735b710d583763wrowe<h2><a name="flag_ne" id="flag_ne">NE|noescape</a></h2>
700b96db75e7cfadb5219978c1735b710d583763wrowe<p>By default, special characters, such as <code>&amp;</code> and
700b96db75e7cfadb5219978c1735b710d583763wrowe<code>?</code>, for example, will be converted to their hexcode
700b96db75e7cfadb5219978c1735b710d583763wroweequivalent. Using the [NE] flag prevents that from happening.
700b96db75e7cfadb5219978c1735b710d583763wrowe</p>
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe<div class="example"><p><code>
700b96db75e7cfadb5219978c1735b710d583763wroweRewriteRule ^/anchor/(.+) /bigpage.html#$1 [NE,R]
700b96db75e7cfadb5219978c1735b710d583763wrowe</code></p></div>
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe<p>
700b96db75e7cfadb5219978c1735b710d583763wroweThe above example will redirect <code>/anchor/xyz</code> to
700b96db75e7cfadb5219978c1735b710d583763wrowe<code>/bigpage.html#xyz</code>. Omitting the [NE] will result in the #
103a93c625bcde1a6a7a5155b64dcda36f612180pquernabeing converted to its hexcode equivalent, <code>%23</code>, which will
103a93c625bcde1a6a7a5155b64dcda36f612180pquernathen result in a 404 Not Found error condition.
103a93c625bcde1a6a7a5155b64dcda36f612180pquerna</p>
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
700b96db75e7cfadb5219978c1735b710d583763wrowe<div class="section">
8aefbd756763807188d2e3ce336a8680e4893066wrowe<h2><a name="flag_ns" id="flag_ns">NS|nosubreq</a></h2>
8aefbd756763807188d2e3ce336a8680e4893066wrowe<p>Use of the [NS] flag prevents the rule from being used on
8aefbd756763807188d2e3ce336a8680e4893066wrowesubrequests. For example, a page which is included using an SSI (Server
8aefbd756763807188d2e3ce336a8680e4893066wroweSide Include) is a subrequest, and you may want to avoid rewrites
8aefbd756763807188d2e3ce336a8680e4893066wrowehappening on those subrequests. Also, when <code class="module"><a href="/mod/mod_dir.html">mod_dir</a></code>
8aefbd756763807188d2e3ce336a8680e4893066wrowetries to find out information about possible directory default files
8aefbd756763807188d2e3ce336a8680e4893066wrowe(such as <code>index.html</code> files), this is an internal
8aefbd756763807188d2e3ce336a8680e4893066wrowesubrequest, and you often want to avoid rewrites on such subrequests.
8aefbd756763807188d2e3ce336a8680e4893066wroweOn subrequests, it is not always useful, and can even cause errors, if
8aefbd756763807188d2e3ce336a8680e4893066wrowethe complete set of rules are applied. Use this flag to exclude
8aefbd756763807188d2e3ce336a8680e4893066wroweproblematic rules.</p>
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe<p>To decide whether or not to use this rule: if you prefix URLs with
8aefbd756763807188d2e3ce336a8680e4893066wroweCGI-scripts, to force them to be processed by the CGI-script, it's
8aefbd756763807188d2e3ce336a8680e4893066wrowelikely that you will run into problems (or significant overhead)
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwroweon sub-requests. In these cases, use this flag.</p>
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<p>
8aefbd756763807188d2e3ce336a8680e4893066wroweImages, javascript files, or css files, loaded as part of an HTML page,
8aefbd756763807188d2e3ce336a8680e4893066wroweare not subrequests - the browser requests them as separate HTTP
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowerequests.
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe</p>
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<div class="section">
8aefbd756763807188d2e3ce336a8680e4893066wrowe<h2><a name="flag_p" id="flag_p">P|proxy</a></h2>
8aefbd756763807188d2e3ce336a8680e4893066wrowe<p>Use of the [P] flag causes the request to be handled by
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe<code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code>, and handled via a proxy request. For
a8d11d78181478da6a672f7fbc58b8d523351f49wroweexample, if you wanted all image requests to be handled by a back-end
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerimage server, you might do something like the following:</p>
23c6309e36a63b13b61c35999c978017521993d6wrowe
23c6309e36a63b13b61c35999c978017521993d6wrowe<div class="example"><p><code>
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerRewriteRule /(.*)\.(jpg|gif|png) http://images.example.com/$1.$2 [P]
23c6309e36a63b13b61c35999c978017521993d6wrowe</code></p></div>
8aefbd756763807188d2e3ce336a8680e4893066wrowe
23c6309e36a63b13b61c35999c978017521993d6wrowe<p>Use of the [P] flag implies [L] - that is, the request is immediately
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawickpushed through the proxy, and any following rules will not be
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerconsidered.</p>
23c6309e36a63b13b61c35999c978017521993d6wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<p>
8aefbd756763807188d2e3ce336a8680e4893066wroweYou must make sure that the substitution string is a valid URI
8aefbd756763807188d2e3ce336a8680e4893066wrowe(typically starting with <code>http://</code><em>hostname</em>) which can be
cf6ef072483172309861d06e85b1aeff4573c060wrowehandled by the <code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code>. If not, you will get an
cf6ef072483172309861d06e85b1aeff4573c060wroweerror from the proxy module. Use this flag to achieve a
cf6ef072483172309861d06e85b1aeff4573c060wrowemore powerful implementation of the <code class="directive"><a href="/mod/mod_proxy.html#proxypass">ProxyPass</a></code> directive,
8aefbd756763807188d2e3ce336a8680e4893066wroweto map remote content into the namespace of the local server.</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<div class="warning">
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<h3>Security Warning</h3>
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick<p>Take care when constructing the target URL of the rule, considering
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowethe security impact from allowing the client influence over the set of
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerURLs to which your server will act as a proxy. Ensure that the scheme
a8d11d78181478da6a672f7fbc58b8d523351f49wroweand hostname part of the URL is either fixed, or does not allow the
e4a3f3c2f080cac75a15a6454cca429b8161c050wroweclient undue influence.</p>
8aefbd756763807188d2e3ce336a8680e4893066wrowe</div>
8aefbd756763807188d2e3ce336a8680e4893066wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe<p>Note: <code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code> must be enabled in order
cf6ef072483172309861d06e85b1aeff4573c060wroweto use this flag.</p>
cf6ef072483172309861d06e85b1aeff4573c060wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
cf6ef072483172309861d06e85b1aeff4573c060wrowe<div class="section">
cf6ef072483172309861d06e85b1aeff4573c060wrowe<h2><a name="flag_pt" id="flag_pt">PT|passthrough</a></h2>
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp
cf6ef072483172309861d06e85b1aeff4573c060wrowe<p>
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerThe target (or substitution string) in a RewriteRule is assumed to be a
cf6ef072483172309861d06e85b1aeff4573c060wrowefile path, by default. The use of the [PT] flag causes it to be treated
cf6ef072483172309861d06e85b1aeff4573c060wroweas a URI instead. That is to say, the
cf6ef072483172309861d06e85b1aeff4573c060wroweuse of the [PT] flag causes the result of the <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> to be passed back through
cf6ef072483172309861d06e85b1aeff4573c060wroweURL mapping, so that location-based mappings, such as <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>, <code class="directive"><a href="/mod/core.html#redirect">Redirect</a></code>, or <code class="directive"><a href="/mod/mod_alias.html#scriptalias">ScriptAlias</a></code>, for example, might have a
cf6ef072483172309861d06e85b1aeff4573c060wrowechance to take effect.
cf6ef072483172309861d06e85b1aeff4573c060wrowe</p>
cf6ef072483172309861d06e85b1aeff4573c060wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe<p>
cf6ef072483172309861d06e85b1aeff4573c060wroweIf, for example, you have an
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe<code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>
ecde48c75338ff5712f2036711f813c6dedca28ewrowefor /icons, and have a <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> pointing there, you should
d75626f0952c6152a99acd013a4f127d46f0f9edtrawickuse the [PT] flag to ensure that the
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick<code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code> is evaluated.
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick</p>
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick<div class="example"><p><code>
d75626f0952c6152a99acd013a4f127d46f0f9edtrawickAlias /icons /usr/local/apache/icons<br />
d75626f0952c6152a99acd013a4f127d46f0f9edtrawickRewriteRule /pics/(.+)\.jpg /icons/$1.gif [PT]
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick</code></p></div>
ecde48c75338ff5712f2036711f813c6dedca28ewrowe
ecde48c75338ff5712f2036711f813c6dedca28ewrowe<p>
d75626f0952c6152a99acd013a4f127d46f0f9edtrawickOmission of the [PT] flag in this case will cause the Alias to be
ecde48c75338ff5712f2036711f813c6dedca28ewroweignored, resulting in a 'File not found' error being returned.
ecde48c75338ff5712f2036711f813c6dedca28ewrowe</p>
ecde48c75338ff5712f2036711f813c6dedca28ewrowe
ecde48c75338ff5712f2036711f813c6dedca28ewrowe<p>The <code>PT</code> flag implies the <code>L</code> flag:
ecde48c75338ff5712f2036711f813c6dedca28ewrowerewriting will be stopped in order to pass the request to
d75626f0952c6152a99acd013a4f127d46f0f9edtrawickthe next phase of processing.</p>
cf6ef072483172309861d06e85b1aeff4573c060wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe<p>Note that the <code>PT</code> flag is implied in per-directory
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarcontexts such as
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code> sections
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoaror in <code>.htaccess</code> files. The only way to circumvent that
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoaris to rewrite to <code>-</code>.</p>
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<div class="section">
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<h2><a name="flag_qsa" id="flag_qsa">QSA|qsappend</a></h2>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>
e4a3f3c2f080cac75a15a6454cca429b8161c050wroweWhen the replacement URI contains a query string, the default behavior
e4a3f3c2f080cac75a15a6454cca429b8161c050wroweof <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> is to discard
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerthe existing query string, and replace it with the newly generated one.
23c6309e36a63b13b61c35999c978017521993d6wroweUsing the [QSA] flag causes the query strings to be combined.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>Consider the following rule:</p>
c2cf53a40a9814eb91db2cdf820f97d943f21628coar
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<div class="example"><p><code>
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerRewriteRule /pages/(.+) /page.php?page=$1 [QSA]
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe</code></p></div>
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<p>With the [QSA] flag, a request for <code>/pages/123?one=two</code> will be
a9a4544168a37b43bd180b3703ccee995f27a80awrowemapped to <code>/page.php?page=123&amp;one=two</code>. Without the [QSA]
e4a3f3c2f080cac75a15a6454cca429b8161c050wroweflag, that same request will be mapped to
a9a4544168a37b43bd180b3703ccee995f27a80awrowe<code>/page.php?page=123</code> - that is, the existing query string
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerwill be discarded.
a9a4544168a37b43bd180b3703ccee995f27a80awrowe</p>
a9a4544168a37b43bd180b3703ccee995f27a80awrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
a9a4544168a37b43bd180b3703ccee995f27a80awrowe<div class="section">
a9a4544168a37b43bd180b3703ccee995f27a80awrowe<h2><a name="flag_qsd" id="flag_qsd">QSD|qsdiscard</a></h2>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarWhen the requested URI contains a query string, and the target URI does
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowenot, the default behavior of <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> is to copy that query
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarstring to the target URI. Using the [QSD] flag causes the query string
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarto be discarded.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe</p>
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>This flag is available in version 2.4.0 and later.</p>
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe<p>
e4a3f3c2f080cac75a15a6454cca429b8161c050wroweUsing [QSD] and [QSA] together will result in [QSD] taking precedence.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe</p>
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<p>
700b96db75e7cfadb5219978c1735b710d583763wroweIf the target URI has a query string, the default behavior will be
cf6ef072483172309861d06e85b1aeff4573c060wroweobserved - that is, the original query string will be discarded and
cf6ef072483172309861d06e85b1aeff4573c060wrowereplaced with the query string in the <code>RewriteRule</code> target
e4a3f3c2f080cac75a15a6454cca429b8161c050wroweURI.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe</p>
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz<div class="section">
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz<h2><a name="flag_r" id="flag_r">R|redirect</a></h2>
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz<p>
cf6ef072483172309861d06e85b1aeff4573c060wroweUse of the [R] flag causes a HTTP redirect to be issued to the browser.
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweIf a fully-qualified URL is specified (that is, including
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<code>http://servername/</code>) then a redirect will be issued to that
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowelocation. Otherwise, the current protocol, servername, and port number
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerwill be used to generate the URL sent with the redirect.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe</p>
2fd8d1e14fc47762d1e01660b544d5e2a75c825dtrawick
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<p>
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe<em>Any</em> valid HTTP response status code may be specified,
e4a3f3c2f080cac75a15a6454cca429b8161c050wroweusing the syntax [R=305], with a 302 status code being used by
8aefbd756763807188d2e3ce336a8680e4893066wrowedefault if none is specified. The status code specified need not
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowenecessarily be a redirect (3xx) status code.
700b96db75e7cfadb5219978c1735b710d583763wrowe</p>
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe<p>If a status code is outside the redirect range (300-399) then the
700b96db75e7cfadb5219978c1735b710d583763wrowesubstitution string is dropped entirely, and rewriting is stopped as if
8aefbd756763807188d2e3ce336a8680e4893066wrowethe <code>L</code> were used.</p>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>In addition to response status codes, you may also specify redirect
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowestatus using their symbolic names: <code>temp</code> (default),
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<code>permanent</code>, or <code>seeother</code>.</p>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<p>
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweYou will almost always want to use [R] in conjunction with [L] (that is,
59513b1275fdc2021d4949ee03ae8229469abb86wroweuse [R,L]) because on its own, the [R] flag prepends
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<code>http://thishost[:thisport]</code> to the URI, but then passes this
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweon to the next rule in the ruleset, which can often result in 'Invalid
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerURI in request' warnings.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker</p>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<div class="section">
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<h2><a name="flag_s" id="flag_s">S|skip</a></h2>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>The [S] flag is used to skip rules that you don't want to run. This
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowecan be thought of as a <code>goto</code> statement in your rewrite
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweruleset. In the following example, we only want to run the <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> if the requested URI
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowedoesn't correspond with an actual file.</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<div class="example"><p><code>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe# Is the request for a non-existent file?<br />
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweRewriteCond %{REQUEST_FILENAME} !-f<br />
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweRewriteCond %{REQUEST_FILENAME} !-d<br />
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe# If so, skip these two RewriteRules<br />
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweRewriteRule .? - [S=2]<br />
cf6ef072483172309861d06e85b1aeff4573c060wrowe<br />
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweRewriteRule (.*\.gif) images.php?$1<br />
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweRewriteRule (.*\.html) docs.php?$1
4f9c22c4f27571d54197be9674e1fc0d528192aestriker</code></p></div>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>This technique is useful because a <code class="directive"><a href="/mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> only applies to the
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> immediately
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowefollowing it. Thus, if you want to make a <code>RewriteCond</code> apply
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweto several <code>RewriteRule</code>s, one possible technique is to
4f9c22c4f27571d54197be9674e1fc0d528192aestrikernegate those conditions and use a [Skip] flag. So, you can
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweuse this to make pseudo if-then-else constructs: The last rule of
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerthe then-clause becomes <code>skip=N</code>, where N is the
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowenumber of rules in the else-clause.</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<div class="section">
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<h2><a name="flag_t" id="flag_t">T|type</a></h2>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<p>Sets the MIME type with which the resulting response will be
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowesent. This has the same effect as the <code class="directive"><a href="/mod/mod_mime.html#addtype">AddType</a></code> directive.</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<p>For example, you might use the following technique to serve Perl
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowesource code as plain text, if requested in a particular way:</p>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<div class="example"><p><code>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe# Serve .pl files as plain text<br />
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweRewriteRule \.pl$ - [T=text/plain]
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe</code></p></div>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<p>Or, perhaps, if you have a camera that produces jpeg images without
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowefile extensions, you could force those images to be served with the
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowecorrect MIME type by virtue of their file names:</p>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<div class="example"><p><code>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe# Files with 'IMG' in the name are jpg images.<br />
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweRewriteRule IMG - [T=image/jpg]
cf6ef072483172309861d06e85b1aeff4573c060wrowe</code></p></div>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<p>Please note that this is a trivial example, and could be better done
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweusing <code class="directive"><a href="/mod/core.html#filesmatch">&lt;FilesMatch&gt;</a></code>
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweinstead. Always consider the alternate
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowesolutions to a problem before resorting to rewrite, which will
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweinvariably be a less efficient solution than the alternatives.</p>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<p>
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweIf used in per-directory context, use only <code>-</code> (dash)
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweas the substitution <em>for the entire round of mod_rewrite processing</em>,
1b315ee865b0f11e582beb64127ca3a99a319d2fwroweotherwise the MIME-type set with this flag is lost due to an internal
38bcc87d9a06e8ba81165421403f275eca4e313btrawickre-processing (including subsequent rounds of mod_rewrite processing).
38bcc87d9a06e8ba81165421403f275eca4e313btrawickThe <code>L</code> flag can be useful in this context to end the
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<em>current</em> round of mod_rewrite processing.</p>
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe</div></div>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<div class="bottomlang">
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<p><span>Available Languages: </span><a href="/en/rewrite/flags.html" title="English">&nbsp;en&nbsp;</a> |
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<a href="/fr/rewrite/flags.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe</div><div id="footer">
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe<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>
4f9c22c4f27571d54197be9674e1fc0d528192aestriker<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>
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe</body></html>