flags.xml revision de3cbd6fee02db3e7a0b3396fb20375c58a18cec
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<!-- $LastChangedRevision: 158972 $ -->
de3cbd6fee02db3e7a0b3396fb20375c58a18cecrbowen Copyright 2002-2006 The Apache Software Foundation or its licensors, as
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen applicable.
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen Licensed under the Apache License, Version 2.0 (the "License");
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen you may not use this file except in compliance with the License.
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen You may obtain a copy of the License at
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen Unless required by applicable law or agreed to in writing, software
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen distributed under the License is distributed on an "AS IS" BASIS,
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen See the License for the specific language governing permissions and
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen limitations under the License.
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>This document discusses the flags which are available to the
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<directive module="mod_rewrite">RewriteRule</directive> directive,
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenproviding more detailed explanations and examples of each.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<seealso><a href="/mod/mod_rewrite.html">Module documentation</a></seealso>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<seealso><a href="rewrite_tech.html">Technical details</a></seealso>
e953a3ed43a5521c980dbd1c1390d14b7f903b85rbowen<seealso><a href="rewrite_guide.html">Rewrite Guide - useful examples</a></seealso>
e953a3ed43a5521c980dbd1c1390d14b7f903b85rbowen<seealso><a href="rewrite_guide_advanced.html">Advanced Rewrite Guide -
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<section id="introduction"><title>Introduction</title>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p><directive module="mod_rewrite">RewriteRule</directive>s can have
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowentheir behavior modified by one or more flags. Flags are included in
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowensquare brackets at the end of the rule, and multiple flags are separated
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenby commas.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenRewriteRule pattern target [Flag1,Flag2,Flag3]
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>The flags all have a short form, such as <code>CO</code>, as well as
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowena longer form, such as <code>cookie</code>. Some flags take one or more
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenarguments. Flags are not case sensitive.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>Each flag has a long and short form. While it is most common to use
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenthe short form, it is recommended that you familiarize yourself with the
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenlong form, so that you remember what each flag is supposed to do.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>Presented here are each of the available flags, along with an example
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenof how you might use them.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>The [C] or [chain] flag indicates that the <directive
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenmodule="mod_rewrite">RewriteRule</directive> is chained to the next
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenrule. That is, if the rule matches, then it is processed as usual and
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowencontrol moves on to the next rule. However, if it does not match, then
e953a3ed43a5521c980dbd1c1390d14b7f903b85rbowenthe next rule, and any other rules that are chained together, will be
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenskipped.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>The [CO], or [cookie] flag, allows you to set a cookie when a
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenparticular <directive module="mod_rewrite">RewriteRule</directive>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenmatches. The argument consists of three required fields and two optional
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>You must declare a name and value for the cookie to be set, and the
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowendomain for which you wish the cookie to be valid. You may optionally set
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenthe lifetime of the cookie, and the path for which it should be
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenreturned.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>By default, the lifetime of the cookie is the current browser
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowensession.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>By default, the path for which the cookie will be valid is "/" - that
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenis, the entire website.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenRewriteEngine On<br />
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenRewriteRule ^/index.html - [CO=frontdoor=yes:.apache.org:1440:/]
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>This rule doesn't rewrite the request (the "-" rewrite target tells
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenmod_rewrite to pass the request through unchanged) but sets a cookie
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowencalled 'frontdoor' to a value of 'yes'. The cookie is valid for any host
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenin the <code>.apache.org</code> domain. It will be set to expire in 1440
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenminutes (24 hours) and will be returned for all URIs.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>With the [E], or [env] flag, you can set the value of an environment
e953a3ed43a5521c980dbd1c1390d14b7f903b85rbowenvariable. Note that some environment variables may be set after the rule
e953a3ed43a5521c980dbd1c1390d14b7f903b85rbowenis run, thus unsetting what you have set. See <a href="/env.html">the
e953a3ed43a5521c980dbd1c1390d14b7f903b85rbowenEnvironment Variables document</a> for more details on how Environment
e953a3ed43a5521c980dbd1c1390d14b7f903b85rbowenvariables work.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>The following example sets an evironment variable called 'image' to a
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenvalue of '1' if the requested URI is an image file. Then, that
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenenvironment variable is used to exclude those requests from the access
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenRewriteRule %{REQUEST_URI} \.(png|gif|jpg) - [E=image:1]<br />
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen<p>Note that this same effect can be obtained using <directive
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenmodule="mod_setenvif">SetEnvIf</directive>. This technique is offered as
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowenan example, not as a recommendation.</p>
7259bc5c18cdd9d115e639af8956b28081c5d7f0rbowen</manualpage>