flags.html.en revision 838b38125778ec117a35c73c92a1dfdecb3c503e
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim This file is generated from xml source: DO NOT EDIT
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<title>Apache mod_rewrite Flags - Apache HTTP Server</title>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<link href="/images/favicon.ico" rel="shortcut icon" /></head>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<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>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<div class="up"><a href="/index.html"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.3</a></div><div id="page-content"><div id="preamble"><h1>Apache mod_rewrite Flags</h1>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p><span>Available Languages: </span><a href="/en/rewrite/flags.html" title="English"> en </a></p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>This document discusses the flags which are available to the
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> directive,
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimproviding more detailed explanations and examples of each.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#introduction">Introduction</a></li>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<li><img alt="" src="/images/down.gif" /> <a href="#flags">The flags</a></li>
834fc281be8e0f7f2614961f12d8bbf603382a17jfclere</ul><h3>See also</h3><ul class="seealso"><li><a href="/mod/mod_rewrite.html">Module documentation</a></li><li><a href="rewrite_tech.html">Technical details</a></li><li><a href="rewrite_guide.html">Rewrite Guide - useful examples</a></li><li><a href="rewrite_guide_advanced.html">Advanced Rewrite Guide -
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<h2><a name="introduction" id="introduction">Introduction</a></h2>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p><code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>s can have
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimtheir behavior modified by one or more flags. Flags are included in
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimsquare brackets at the end of the rule, and multiple flags are separated
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimby commas.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimRewriteRule pattern target [Flag1,Flag2,Flag3]
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>The flags all have a short form, such as <code>CO</code>, as well as
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jima longer form, such as <code>cookie</code>. Some flags take one or more
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimarguments. Flags are not case sensitive.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>Each flag has a long and short form. While it is most common to use
834fc281be8e0f7f2614961f12d8bbf603382a17jfclerethe short form, it is recommended that you familiarize yourself with the
834fc281be8e0f7f2614961f12d8bbf603382a17jfclerelong form, so that you remember what each flag is supposed to do.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>Presented here are each of the available flags, along with an example
834fc281be8e0f7f2614961f12d8bbf603382a17jfclereof how you might use them.</p>
834fc281be8e0f7f2614961f12d8bbf603382a17jfclere<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
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimrule. That is, if the rule matches, then it is processed as usual and
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimcontrol moves on to the next rule. However, if it does not match, then
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimthe next rule, and any other rules that are chained together, will be
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimskipped.</p>
834fc281be8e0f7f2614961f12d8bbf603382a17jfclere<p>The [CO], or [cookie] flag, allows you to set a cookie when a
834fc281be8e0f7f2614961f12d8bbf603382a17jfclereparticular <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimmatches. The argument consists of three required fields and two optional
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimfields.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>You must declare a name and value for the cookie to be set, and the
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimdomain for which you wish the cookie to be valid. You may optionally set
834fc281be8e0f7f2614961f12d8bbf603382a17jfclerethe lifetime of the cookie, and the path for which it should be
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimreturned.</p>
834fc281be8e0f7f2614961f12d8bbf603382a17jfclere<p>By default, the lifetime of the cookie is the current browser
834fc281be8e0f7f2614961f12d8bbf603382a17jfcleresession.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>By default, the path for which the cookie will be valid is "/" - that
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimis, the entire website.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimRewriteEngine On<br />
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimRewriteRule ^/index.html - [CO=frontdoor=yes:.apache.org:1440:/]
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>This rule doesn't rewrite the request (the "-" rewrite target tells
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimmod_rewrite to pass the request through unchanged) but sets a cookie
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimcalled 'frontdoor' to a value of 'yes'. The cookie is valid for any host
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimin the <code>.apache.org</code> domain. It will be set to expire in 1440
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimminutes (24 hours) and will be returned for all URIs.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>With the [E], or [env] flag, you can set the value of an environment
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimvariable. Note that some environment variables may be set after the rule
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimis run, thus unsetting what you have set. See <a href="/env.html">the
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimEnvironment Variables document</a> for more details on how Environment
23a31b10f869a72c9197b5f153f4f3e1a4c68f28jimvariables work.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>The following example sets an evironment variable called 'image' to a
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimvalue of '1' if the requested URI is an image file. Then, that
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimenvironment variable is used to exclude those requests from the access
6bed231822ad2aaba16de74c4c01023e5982a5e2jfclereRewriteRule \.(png|gif|jpg) - [E=image:1]<br />
6bed231822ad2aaba16de74c4c01023e5982a5e2jfclere<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
b1e3273c2e70ad5ac64feef979b2ed1d98c09963jiman example, not as a recommendation.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>Using the [F] flag causes Apache to return a 403 Forbidden status
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimcode to the client. While the same behavior can be accomplished using
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimthe <code class="directive"><a href="/mod/mod_access.html#deny">Deny</a></code> directive, this
9a0e1ad272fdbe3fee989e93bdae8253418429edjfclereallows more flexibility in assigning a Forbidden status.</p>
9a0e1ad272fdbe3fee989e93bdae8253418429edjfclere<p>The following rule will forbid <code>.exe</code> files from being
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimdownloaded from your server.</p>
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimRewriteRule \.exe - [F]
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jim<p>This rule uses the "-" syntax for the rewrite target, which means
dfcadcd3e6bbdee594540b8f8e4e50586a2e3219jimthat the requested URI is not modified.</p>
<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
RewriteRule (.*\.(jpg|gif|png))$ http://images.example.com$1 [P,NC]
ruleset. 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
RewriteRule (.*\.html) docs.php?$1
<p>This technique is useful because a <code class="directive"><a href="/mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> only applies to the
<code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> immediately
sent. This has the same effect as the <code class="directive"><a href="/mod/mod_mime.html#addtype">AddType</a></code> directive.</p>
<p><span>Available Languages: </span><a href="/en/rewrite/flags.html" title="English"> en </a></p>
<p class="apache">Copyright 2006 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>