flags.xml revision 76a5ef0bb4d1ae6dc673b6006b284879df90a093
af84459fbf938e508fd10b01cb8d699c79083813takashi<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
af84459fbf938e508fd10b01cb8d699c79083813takashi<!-- $LastChangedRevision$ -->
af84459fbf938e508fd10b01cb8d699c79083813takashi Licensed to the Apache Software Foundation (ASF) under one or more
af84459fbf938e508fd10b01cb8d699c79083813takashi contributor license agreements. See the NOTICE file distributed with
af84459fbf938e508fd10b01cb8d699c79083813takashi this work for additional information regarding copyright ownership.
af84459fbf938e508fd10b01cb8d699c79083813takashi The ASF licenses this file to You under the Apache License, Version 2.0
af84459fbf938e508fd10b01cb8d699c79083813takashi (the "License"); you may not use this file except in compliance with
af84459fbf938e508fd10b01cb8d699c79083813takashi the License. You may obtain a copy of the License at
af84459fbf938e508fd10b01cb8d699c79083813takashi Unless required by applicable law or agreed to in writing, software
af84459fbf938e508fd10b01cb8d699c79083813takashi distributed under the License is distributed on an "AS IS" BASIS,
af84459fbf938e508fd10b01cb8d699c79083813takashi WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
af84459fbf938e508fd10b01cb8d699c79083813takashi See the License for the specific language governing permissions and
af84459fbf938e508fd10b01cb8d699c79083813takashi limitations under the License.
3c13a815670b54d1c17bf02954f7d2b066cde95cnd<p>This document discusses the flags which are available to the
3c13a815670b54d1c17bf02954f7d2b066cde95cnd<directive module="mod_rewrite">RewriteRule</directive> directive,
af84459fbf938e508fd10b01cb8d699c79083813takashiproviding more detailed explanations and examples of each.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<seealso><a href="/mod/mod_rewrite.html">Module documentation</a></seealso>
af84459fbf938e508fd10b01cb8d699c79083813takashi<seealso><a href="rewrite_tech.html">Technical details</a></seealso>
af84459fbf938e508fd10b01cb8d699c79083813takashi<seealso><a href="rewrite_guide.html">Rewrite Guide - useful examples</a></seealso>
af84459fbf938e508fd10b01cb8d699c79083813takashi<seealso><a href="rewrite_guide_advanced.html">Advanced Rewrite Guide -
af84459fbf938e508fd10b01cb8d699c79083813takashi<section id="introduction"><title>Introduction</title>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p><directive module="mod_rewrite">RewriteRule</directive>s can have
af84459fbf938e508fd10b01cb8d699c79083813takashitheir behavior modified by one or more flags. Flags are included in
af84459fbf938e508fd10b01cb8d699c79083813takashisquare brackets at the end of the rule, and multiple flags are separated
af84459fbf938e508fd10b01cb8d699c79083813takashiby commas.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashiRewriteRule pattern target [Flag1,Flag2,Flag3]
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>The flags all have a short form, such as <code>CO</code>, as well as
af84459fbf938e508fd10b01cb8d699c79083813takashia longer form, such as <code>cookie</code>. Some flags take one or more
af84459fbf938e508fd10b01cb8d699c79083813takashiarguments. Flags are not case sensitive.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>Each flag has a long and short form. While it is most common to use
af84459fbf938e508fd10b01cb8d699c79083813takashithe short form, it is recommended that you familiarize yourself with the
af84459fbf938e508fd10b01cb8d699c79083813takashilong form, so that you remember what each flag is supposed to do.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>Presented here are each of the available flags, along with an example
af84459fbf938e508fd10b01cb8d699c79083813takashiof how you might use them.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>The [C] or [chain] flag indicates that the <directive
af84459fbf938e508fd10b01cb8d699c79083813takashimodule="mod_rewrite">RewriteRule</directive> is chained to the next
af84459fbf938e508fd10b01cb8d699c79083813takashirule. That is, if the rule matches, then it is processed as usual and
af84459fbf938e508fd10b01cb8d699c79083813takashicontrol moves on to the next rule. However, if it does not match, then
af84459fbf938e508fd10b01cb8d699c79083813takashithe next rule, and any other rules that are chained together, will be
af84459fbf938e508fd10b01cb8d699c79083813takashiskipped.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>The [CO], or [cookie] flag, allows you to set a cookie when a
af84459fbf938e508fd10b01cb8d699c79083813takashiparticular <directive module="mod_rewrite">RewriteRule</directive>
af84459fbf938e508fd10b01cb8d699c79083813takashimatches. The argument consists of three required fields and two optional
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>You must declare a name and value for the cookie to be set, and the
af84459fbf938e508fd10b01cb8d699c79083813takashidomain for which you wish the cookie to be valid. You may optionally set
0cf3cdbaa1dad11cbf1ce32e48f1b4ec88cf779fnilgunthe lifetime of the cookie, and the path for which it should be
af84459fbf938e508fd10b01cb8d699c79083813takashireturned.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>By default, the lifetime of the cookie is the current browser
af84459fbf938e508fd10b01cb8d699c79083813takashisession.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>By default, the path for which the cookie will be valid is "/" - that
af84459fbf938e508fd10b01cb8d699c79083813takashiis, the entire website.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashiRewriteEngine On<br />
af84459fbf938e508fd10b01cb8d699c79083813takashiRewriteRule ^/index.html - [CO=frontdoor=yes:.apache.org:1440:/]
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>This rule doesn't rewrite the request (the "-" rewrite target tells
af84459fbf938e508fd10b01cb8d699c79083813takashimod_rewrite to pass the request through unchanged) but sets a cookie
af84459fbf938e508fd10b01cb8d699c79083813takashicalled 'frontdoor' to a value of 'yes'. The cookie is valid for any host
af84459fbf938e508fd10b01cb8d699c79083813takashiin the <code>.apache.org</code> domain. It will be set to expire in 1440
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrinminutes (24 hours) and will be returned for all URIs.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>With the [E], or [env] flag, you can set the value of an environment
af84459fbf938e508fd10b01cb8d699c79083813takashivariable. Note that some environment variables may be set after the rule
af84459fbf938e508fd10b01cb8d699c79083813takashiis run, thus unsetting what you have set. See <a href="/env.html">the
af84459fbf938e508fd10b01cb8d699c79083813takashiEnvironment Variables document</a> for more details on how Environment
af84459fbf938e508fd10b01cb8d699c79083813takashivariables work.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>The following example sets an evironment variable called 'image' to a
af84459fbf938e508fd10b01cb8d699c79083813takashivalue of '1' if the requested URI is an image file. Then, that
af84459fbf938e508fd10b01cb8d699c79083813takashienvironment variable is used to exclude those requests from the access
af84459fbf938e508fd10b01cb8d699c79083813takashiRewriteRule \.(png|gif|jpg) - [E=image:1]<br />
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>Note that this same effect can be obtained using <directive
af84459fbf938e508fd10b01cb8d699c79083813takashimodule="mod_setenvif">SetEnvIf</directive>. This technique is offered as
af84459fbf938e508fd10b01cb8d699c79083813takashian example, not as a recommendation.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>Using the [F] flag causes Apache to return a 403 Forbidden status
af84459fbf938e508fd10b01cb8d699c79083813takashicode to the client. While the same behavior can be accomplished using
af84459fbf938e508fd10b01cb8d699c79083813takashithe <directive module="mod_access">Deny</directive> directive, this
af84459fbf938e508fd10b01cb8d699c79083813takashiallows more flexibility in assigning a Forbidden status.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>The following rule will forbid <code>.exe</code> files from being
af84459fbf938e508fd10b01cb8d699c79083813takashidownloaded from your server.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashiRewriteRule \.exe - [F]
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>This rule uses the "-" syntax for the rewrite target, which means
af84459fbf938e508fd10b01cb8d699c79083813takashithat the requested URI is not modified.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashimodule="mod_rewrite">RewriteRule</directive> to be matched in a
af84459fbf938e508fd10b01cb8d699c79083813takashicase-insensitive manner. That is, it doesn't care whether letters appear
af84459fbf938e508fd10b01cb8d699c79083813takashias upper-case or lower-case in the matched URI.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>In the example below, any request for an image file will be proxied
af84459fbf938e508fd10b01cb8d699c79083813takashito your dedicated image server. The match is case-insensitive, so that
af84459fbf938e508fd10b01cb8d699c79083813takashi<code>.jpg</code> and <code>.JPG</code> files are both acceptable, for
af84459fbf938e508fd10b01cb8d699c79083813takashiexample.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashiRewriteRule (.*\.(jpg|gif|png))$ http://images.example.com$1 [P,NC]
af84459fbf938e508fd10b01cb8d699c79083813takashi<p>The [S] flag is used to skip rules that you don't want to run. This
af84459fbf938e508fd10b01cb8d699c79083813takashican be thought of as a <code>goto</code> statement in your rewrite
af84459fbf938e508fd10b01cb8d699c79083813takashiruleset. In the following example, we only want to run the <directive
af84459fbf938e508fd10b01cb8d699c79083813takashimodule="mod_rewrite">RewriteRule</directive> if the requested URI
af84459fbf938e508fd10b01cb8d699c79083813takashidoesn't correspond with an actual file.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashiRewriteCond %{REQUEST_FILENAME} !-f<br />
af84459fbf938e508fd10b01cb8d699c79083813takashiRewriteCond %{REQUEST_FILENAME} !-d<br />
af84459fbf938e508fd10b01cb8d699c79083813takashiRewriteRule .? - [S=2]<br />
af84459fbf938e508fd10b01cb8d699c79083813takashiRewriteRule (.*\.html) docs.php?$1
af84459fbf938e508fd10b01cb8d699c79083813takashimodule="mod_rewrite">RewriteCond</directive> only applies to the
af84459fbf938e508fd10b01cb8d699c79083813takashi<directive module="mod_rewrite">RewriteRule</directive> immediately
af84459fbf938e508fd10b01cb8d699c79083813takashifollowing it. Thus, if you want to make a <code>RewriteCond</code> apply
af84459fbf938e508fd10b01cb8d699c79083813takashito several <code>RewriteRule</code>s, one possible technique is to
af84459fbf938e508fd10b01cb8d699c79083813takashinegate those conditions and use a [Skip] flag.</p>
af84459fbf938e508fd10b01cb8d699c79083813takashi</manualpage>