]> granicus.if.org Git - apache/blob - docs/manual/rewrite/flags.xml
Allow to set environment variables using mod_rewrite without
[apache] / docs / manual / rewrite / flags.xml
1 <?xml version='1.0' encoding='UTF-8' ?>
2 <!DOCTYPE manualpage SYSTEM "../style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="flags.xml.meta">
24 <parentdocument href="./">Rewrite</parentdocument>
25
26   <title>RewriteRule Flags</title>
27
28 <summary>
29 <p>This document discusses the flags which are available to the
30 <directive module="mod_rewrite">RewriteRule</directive> directive,
31 providing detailed explanations and examples.</p>
32 </summary>
33
34 <seealso><a href="../mod/mod_rewrite.html">Module documentation</a></seealso>
35 <seealso><a href="intro.html">mod_rewrite introduction</a></seealso>
36 <seealso><a href="remapping.html">Redirection and remapping</a></seealso>
37 <seealso><a href="access.html">Controlling access</a></seealso>
38 <seealso><a href="vhosts.html">Virtual hosts</a></seealso>
39 <seealso><a href="proxy.html">Proxying</a></seealso>
40 <seealso><a href="rewritemap.html">Using RewriteMap</a></seealso>
41 <seealso><a href="advanced.html">Advanced techniques and tricks</a></seealso>
42 <seealso><a href="avoid.html">When not to use mod_rewrite</a></seealso>
43
44 <section id="introduction"><title>Introduction</title>
45 <p>A <directive module="mod_rewrite">RewriteRule</directive> can have
46 its behavior modified by one or more flags. Flags are included in
47 square brackets at the end of the rule, and multiple flags are separated
48 by commas.</p>
49 <example>
50 RewriteRule pattern target [Flag1,Flag2,Flag3]
51 </example>
52
53 <p>The flags all have a short form, such as <code>CO</code>, as well as
54 a longer form, such as <code>cookie</code>. Some flags take one or more
55 arguments. Flags are not case sensitive.</p>
56
57 <p>Each flag (with a few exceptions) 
58 has a long and short form. While it is most common to use
59 the short form, it is recommended that you familiarize yourself with the
60 long form, so that you remember what each flag is supposed to do.</p>
61
62 <p>Presented here are each of the available flags, along with an example
63 of how you might use them.</p>
64 </section>
65
66 <section id="flag_b"><title>B (escape backreferences)</title>
67 <p>The [B] flag instructs <directive
68 module="mod_rewrite">RewriteRule</directive> to escape non-alphanumeric
69 characters before applying the transformation.
70 </p>
71
72 <p><code>mod_rewrite</code> has to unescape URLs before mapping them,
73 so backreferences will be unescaped at the time they are applied.
74 Using the B flag, non-alphanumeric characters in backreferences
75 will be escaped. For example, consider the rule:</p>
76
77 <example>
78 RewriteRule ^(/.*)$ /index.php?show=$1
79 </example>
80
81 <p>This will map <code>/C++</code> to
82 <code>/index.php?show=/C++</code>. But it will also map
83 <code>/C%2b%2b</code> to <code>/index.php?show=/C++</code>, because
84 the <code>%2b</code> has been unescaped.  With the B flag, it will
85 instead map to <code>/index.php?show=/C%2b%2b</code>.</p>
86
87 <p>This escaping is particularly necessary in a proxy situation,
88 when the backend may break if presented with an unescaped URL.</p>
89
90 </section>
91
92 <section id="flag_c"><title>C|chain</title>
93 <p>The [C] or [chain] flag indicates that the <directive
94 module="mod_rewrite">RewriteRule</directive> is chained to the next
95 rule. That is, if the rule matches, then it is processed as usual and
96 control moves on to the next rule. However, if it does not match, then
97 the next rule, and any other rules that are chained together, will be
98 skipped.</p>
99
100 </section>
101
102 <section id="flag_co"><title>CO|cookie</title>
103 <p>The [CO], or [cookie] flag, allows you to set a cookie when a
104 particular <directive module="mod_rewrite">RewriteRule</directive>
105 matches. The argument consists of three required fields and five optional
106 fields.</p>
107
108 <p>The full syntax for the flag, including all attributes, is as
109 follows:</p>
110
111 <example>
112 [CO=NAME:VALUE:domain:lifetime:path:secure:httponly]
113 </example>
114
115 <p>You must declare a name and value for the cookie to be set.</p>
116
117 <p>You may optionally also set the following values:</p>
118
119 <dl>
120 <dt>Domain</dt>
121 <dd>The domain for which you want the cookie to be valid. This may be a
122 hostname, such as <code>www.example.com</code>, or it may be a domain,
123 such as <code>.example.com</code>. It must be at least two parts
124 separated by a dot. That is, it may not be merely <code>.com</code> or
125 <code>.net</code>. Cookies of that kind are forbidden by the cookie
126 security model.</dd>
127 <dd>The default value for the domain is the current domain.</dd>
128
129 <dt>Lifetime</dt>
130 <dd>The time for which the cookie will persist, in minutes.</dd>
131 <dd>A value of 0 indicates that the cookie will persist only for the
132 current browser session. This is the default value if none is
133 specified.</dd>
134
135 <dt>Path</dt>
136 <dd>The path, on the current website, for which the cookie is valid,
137 such as <code>/customers/</code> or <code>/files/download/</code>.</dd>
138 <dd>By default, this is set to <code>/</code> - that is, the entire
139 website.</dd>
140
141 <dt>Secure</dt>
142 <dd>If set to <code>secure</code>, <code>true</code>, or <code>1</code>,
143 the cookie will only be permitted to be translated via secure (https)
144 connections.</dd>
145
146 <dt>httponly</dt>
147 <dd>If set to <code>HttpOnly</code>, <code>true</code>, or
148 <code>1</code>, the cookie will have the <code>HttpOnly</code> flag set,
149 which means that the cookie will be inaccessible to JavaScript code on
150 browsers that support this feature.</dd>
151 </dl>
152
153 <p>Several examples are offered here:</p>
154
155 <example>
156 RewriteEngine On<br />
157 RewriteRule ^/index\.html - [CO=frontdoor:yes:.apache.org:1440:/]
158 </example>
159
160 <p>In the example give, the rule doesn't rewrite the request.
161 The "-" rewrite target tells mod_rewrite to pass the request
162 through unchanged. Instead, it sets a cookie
163 called 'frontdoor' to a value of 'yes'. The cookie is valid for any host
164 in the <code>.apache.org</code> domain. It will be set to expire in 1440
165 minutes (24 hours) and will be returned for all URIs.</p>
166
167 </section>
168
169 <section id="flag_dpi"><title>DPI|discardpathinfo</title>
170 <p>The DPI flag causes the PATH_INFO portion of the rewritten URI to be
171 discarded.</p>
172 <p>This flag is available in version 2.2.12 and later.</p>
173 <p>In per-directory context, the URI each <directive>RewriteRule</directive>
174 compares against is the concatenation of the current values of the URI
175 and PATH_INFO.</p>
176
177 <p>The current URI can be the initial URI as requested by the client, the
178 result of a previous round of mod_rewrite processing, or the result of
179 a prior rule in the current round of mod_rewrite processing.</p>
180
181 <p>In contrast, the PATH_INFO that is appended to the URI before each
182 rule reflects only the value of PATH_INFO before this round of
183 mod_rewrite processing. As a consequence, if large portions
184 of the URI are matched and copied into a substitution in multiple
185 <directive>RewriteRule</directive> directives, without regard for
186 which parts of the URI came from the current PATH_INFO, the final
187 URI may have multiple copies of PATH_INFO appended to it.</p>
188
189 <p>Use this flag on any substitution where the PATH_INFO that resulted
190 from the previous mapping of this request to the filesystem is not of
191 interest.  This flag permanently forgets the PATH_INFO established
192 before this round of mod_rewrite processing began. PATH_INFO will
193 not be recalculated until the current round of mod_rewrite processing
194 completes.  Subsequent rules during this round of processing will see
195 only the direct result of substitutions, without any PATH_INFO
196 appended.</p>
197 </section>
198
199 <section id="flag_e"><title>E|env</title>
200 <p>With the [E], or [env] flag, you can set the value of an environment
201 variable. Note that some environment variables may be set after the rule
202 is run, thus unsetting what you have set. See <a href="../env.html">the
203 Environment Variables document</a> for more details on how Environment
204 variables work.</p>
205
206 <p>The full syntax for this flag is:</p>
207
208 <example>
209 [E=VAR:VAL]
210 </example>
211
212 <p><code>VAL</code> may contain backreferences (<code>$N</code> or
213 <code>%N</code>) which will be expanded.</p>
214
215 <p>Using the short form</p>
216
217 <example>
218 [E=VAR]
219 </example>
220
221 <p>you can set the environment variable named <code>VAR</code> to an
222 empty value.</p>
223
224 <p>Environment variables can then be used in a variety of
225 contexts, including CGI programs, other RewriteRule directives, or
226 CustomLog directives.</p>
227
228 <p>The following example sets an environment variable called 'image' to a
229 value of '1' if the requested URI is an image file. Then, that
230 environment variable is used to exclude those requests from the access
231 log.</p>
232
233 <example>
234 RewriteRule \.(png|gif|jpg) - [E=image:1]<br />
235 CustomLog logs/access_log combined env=!image
236 </example>
237
238 <p>Note that this same effect can be obtained using <directive
239 module="mod_setenvif">SetEnvIf</directive>. This technique is offered as
240 an example, not as a recommendation.</p>
241 </section>
242
243 <section id="flag_f"><title>F|forbidden</title>
244 <p>Using the [F] flag causes the server to return a 403 Forbidden status
245 code to the client. While the same behavior can be accomplished using
246 the <directive module="mod_access">Deny</directive> directive, this 
247 allows more flexibility in assigning a Forbidden status.</p>
248
249 <p>The following rule will forbid <code>.exe</code> files from being
250 downloaded from your server.</p>
251
252 <example>
253 RewriteRule \.exe - [F]
254 </example>
255
256 <p>This example uses the "-" syntax for the rewrite target, which means
257 that the requested URI is not modified. There's no reason to rewrite to
258 another URI, if you're going to forbid the request.</p>
259
260 <p>When using [F], an [L] is implied - that is, the response is returned
261 immediately, and no further rules are evaluated.</p>
262
263 </section>
264
265 <section id="flag_g"><title>G|gone</title>
266 <p>The [G] flag forces the server to return a 410 Gone status with the
267 response. This indicates that a resource used to be available, but is no
268 longer available.</p>
269
270 <p>As with the [F] flag, you will typically use the "-" syntax for the
271 rewrite target when using the [G] flag:</p>
272
273 <example>
274 RewriteRule oldproduct - [G,NC]
275 </example>
276
277 <p>When using [F], an [L] is implied - that is, the response is returned
278 immediately, and no further rules are evaluated.</p>
279
280 </section>
281
282 <section id="flag_h"><title>H|handler</title>
283 <p>Forces the resulting request to be handled with the specified
284 handler. For example, one might use this to force all files without a
285 file extension to be parsed by the php handler:</p>
286
287 <example>
288 RewriteRule !\. - [H=application/x-httpd-php]
289 </example>
290
291 <p>
292 The regular expression above - <code>!\.</code> - will match any request
293 that does not contain the literal <code>.</code> character.
294 </p>
295
296 <p>This can be also used to force the handler based on some conditions.
297 For example, the following snippet used in per-server context allows
298 <code>.php</code> files to be <em>displayed</em> by <code>mod_php</code>
299 if they are requested with the <code>.phps</code> extension:</p>
300
301 <example>
302 RewriteRule ^(/source/.+\.php)s$ $1 [H=application/x-httpd-php-source]
303 </example>
304
305 <p>The regular expression above - <code>^(/source/.+\.php)s$</code> - will
306 match any request that starts with <code>/source/</code> followed by 1 or
307 n characters followed by <code>.phps</code> literally. The backreference
308 $1 referrers to the captured match within parenthesis of the regular
309 expression.</p>
310 </section>
311
312 <section id="flag_l"><title>L|last</title>
313 <p>The [L] flag causes <module>mod_rewrite</module> to stop processing
314 the rule set. In most contexts, this means that if the rule matches, no
315 further rules will be processed. This corresponds to the
316 <code>last</code> command in Perl, or the <code>break</code> command in
317 C. Use this flag to indicate that the current rule should be applied
318 immediately without considering further rules.</p>
319
320 <p>If you are using <directive
321 module="mod_rewrite">RewriteRule</directive> in either
322 <code>.htaccess</code> files or in 
323 <directive type="section" module="core">Directory</directive> sections,
324 it is important to have some understanding of how the rules are
325 processed.  The simplified form of this is that once the rules have been
326 processed, the rewritten request is handed back to the URL parsing
327 engine to do what it may with it. It is possible that as the rewritten
328 request is handled, the <code>.htaccess</code> file or 
329 <directive type="section" module="core">Directory</directive> section
330 may be encountered again, and thus the ruleset may be run again from the
331 start. Most commonly this will happen if one of the rules causes a
332 redirect - either internal or external - causing the request process to
333 start over.</p>
334
335 <p>It is therefore important, if you are using <directive
336 module="mod_rewrite">RewriteRule</directive> directives in one of these
337 contexts, that you take explicit steps to avoid rules looping, and not
338 count solely on the [L] flag to terminate execution of a series of
339 rules, as shown below.</p>
340
341 <p>The example given here will rewrite any request to
342 <code>index.php</code>, giving the original request as a query string
343 argument to <code>index.php</code>, however, the <directive
344 module="mod_rewrite">RewriteCond</directive> ensures that if the request 
345 is already for <code>index.php</code>, the <directive
346 module="mod_rewrite">RewriteRule</directive> will be skipped.</p>
347
348 <example>
349 RewriteCond %{REQUEST_URI} !=index.php<br />
350 RewriteRule ^(.*) index.php?req=$1 [L]
351 </example>
352 </section>
353
354 <section id="flag_n"><title>N|next</title>
355 <p>
356 The [N] flag causes the ruleset to start over again from the top, using
357 the result of the ruleset so far as a starting point. Use
358 with extreme caution, as it may result in loop.
359 </p>
360 <p>
361 The [Next] flag could be used, for example, if you wished to replace a
362 certain string or letter repeatedly in a request. The example shown here
363 will replace A with B everywhere in a request, and will continue doing
364 so until there are no more As to be replaced.
365 </p>
366
367 <example>
368 RewriteRule (.*)A(.*) $1B$2 [N]
369 </example>
370
371 <p>You can think of this as a <code>while</code> loop: While this
372 pattern still matches (i.e., while the URI still contains an
373 <code>A</code>), perform this substitution (i.e., replace the
374 <code>A</code> with a <code>B</code>).</p>
375
376 </section>
377
378 <section id="flag_nc"><title>NC|nocase</title>
379 <p>Use of the [NC] flag causes the <directive
380 module="mod_rewrite">RewriteRule</directive> to be matched in a
381 case-insensitive manner. That is, it doesn't care whether letters appear
382 as upper-case or lower-case in the matched URI.</p>
383
384 <p>In the example below, any request for an image file will be proxied
385 to your dedicated image server. The match is case-insensitive, so that
386 <code>.jpg</code> and <code>.JPG</code> files are both acceptable, for
387 example.</p>
388
389 <example>
390 RewriteRule (.*\.(jpg|gif|png))$ http://images.example.com$1 [P,NC]
391 </example>
392 </section>
393
394 <section id="flag_ne"><title>NE|noescape</title>
395 <p>By default, special characters, such as <code>&amp;</code> and
396 <code>?</code>, for example, will be converted to their hexcode
397 equivalent. Using the [NE] flag prevents that from happening.
398 </p>
399
400 <example>
401 RewriteRule ^/anchor/(.+) /bigpage.html#$1 [NE,R]
402 </example>
403
404 <p>
405 The above example will redirect <code>/anchor/xyz</code> to
406 <code>/bigpage.html#xyz</code>. Omitting the [NE] will result in the #
407 being converted to its hexcode equivalent, <code>%23</code>, which will
408 then result in a 404 Not Found error condition.
409 </p>
410
411 </section>
412
413 <section id="flag_ns"><title>NS|nosubreq</title>
414 <p>Use of the [NS] flag prevents the rule from being used on
415 subrequests. For example, a page which is included using an SSI (Server
416 Side Include) is a subrequest, and you may want to avoid rewrites
417 happening on those subrequests. Also, when <module>mod_dir</module>
418 tries to find out information about possible directory default files
419 (such as <code>index.html</code> files), this is an internal
420 subrequest, and you often want to avoid rewrites on such subrequests.
421 On subrequests, it is not always useful, and can even cause errors, if
422 the complete set of rules are applied. Use this flag to exclude
423 problematic rules.</p>
424
425 <p>To decide whether or not to use this rule: if you prefix URLs with 
426 CGI-scripts, to force them to be processed by the CGI-script, it's
427 likely that you will run into problems (or significant overhead)
428 on sub-requests. In these cases, use this flag.</p>
429
430 <p>
431 Images, javascript files, or css files, loaded as part of an HTML page,
432 are not subrequests - the browser requests them as separate HTTP
433 requests.
434 </p>
435 </section>
436
437 <section id="flag_p"><title>P|proxy</title>
438 <p>Use of the [P] flag causes the request to be handled by
439 <module>mod_proxy</module>, and handled via a proxy request. For
440 example, if you wanted all image requests to be handled by a back-end
441 image server, you might do something like the following:</p>
442
443 <example>
444 RewriteRule (.*)\.(jpg|gif|png) http://images.example.com$1.$2 [P]
445 </example>
446
447 <p>Use of the [P] flag implies [L] - that is, the request is immediately
448 pushed through the proxy, and any following rules will not be
449 considered.</p>
450
451 <p>
452 You must make sure that the substitution string is a valid URI
453 (typically starting with <code>http://</code><em>hostname</em>) which can be
454 handled by the <module>mod_proxy</module>. If not, you will get an
455 error from the proxy module. Use this flag to achieve a
456 more powerful implementation of the <directive
457 module="mod_proxy">ProxyPass</directive> directive,
458 to map remote content into the namespace of the local server.</p>
459
460 <p>Note: <module>mod_proxy</module> must be enabled in order
461 to use this flag.</p>
462
463 </section>
464
465 <section id="flag_pt"><title>PT|passthrough</title>
466
467 <p>
468 The target (or substitution string) in a RewriteRule is assumed to be a
469 file path, by default. The use of the [PT] flag causes it to be treated
470 as a URI instead. That is to say, the
471 use of the [PT] flag causes the result of the <directive
472 module="mod_rewrite">RewriteRule</directive> to be passed back through
473 URL mapping, so that location-based mappings, such as <directive
474 module="mod_alias">Alias</directive>, <directive
475 module="core">Redirect</directive>, or <directive 
476 module="mod_alias">ScriptAlias</directive>, for example, might have a 
477 chance to take effect.
478 </p>
479
480 <p>
481 If, for example, you have an 
482 <directive module="mod_alias">Alias</directive>
483 for /icons, and have a <directive
484 module="mod_rewrite">RewriteRule</directive> pointing there, you should
485 use the [PT] flag to ensure that the 
486 <directive module="mod_alias">Alias</directive> is evaluated.
487 </p>
488
489 <example>
490 Alias /icons /usr/local/apache/icons<br />
491 RewriteRule /pics/(.+)\.jpg /icons/$1.gif [PT]
492 </example>
493
494 <p>
495 Omission of the [PT] flag in this case will cause the Alias to be
496 ignored, resulting in a 'File not found' error being returned.
497 </p>
498
499 <p>The <code>PT</code> flag implies the <code>L</code> flag:
500 rewriting will be stopped in order to pass the request to
501 the next phase of processing.</p>
502
503 </section>
504
505 <section id="flag_qsa"><title>QSA|qsappend</title>
506 <p>
507 When the replacement URI contains a query string, the default behavior
508 of <directive module="mod_rewrite">RewriteRule</directive> is to discard
509 the existing query string, and replace it with the newly generated one.
510 Using the [QSA] flag causes the query strings to be combined.
511 </p>
512
513 <p>Consider the following rule:</p>
514
515 <example>
516 RewriteRule /pages/(.+) /page.php?page=$1 [QSA]
517 </example>
518
519 <p>With the [QSA] flag, a request for <code>/pages/123?one=two</code> will be
520 mapped to <code>/page.php?page=123&amp;one=two</code>. Without the [QSA]
521 flag, that same request will be mapped to
522 <code>/page.php?page=123</code> - that is, the existing query string
523 will be discarded.
524 </p>
525 </section>
526
527 <section id="flag_qsd"><title>QSD|qsdiscard</title>
528 <p>
529 When the requested URI contains a query string, and the target URI does
530 not, the default behavior of <directive
531 module="mod_rewrite">RewriteRule</directive> is to copy that query
532 string to the target URI. Using the [QSD] flag causes the query string
533 to be discarded.
534 </p>
535
536 <p>This flag is available in version 2.4.0 and later.</p>
537
538 <p>
539 Using [QSD] and [QSA] together will result in [QSD] taking precedence.
540 </p>
541
542 <p>
543 If the target URI has a query string, the default behavior will be
544 observed - that is, the original query string will be discarded and
545 replaced with the query string in the <code>RewriteRule</code> target
546 URI.
547 </p>
548
549 </section>
550
551 <section id="flag_r"><title>R|redirect</title>
552 <p>
553 Use of the [R] flag causes a HTTP redirect to be issued to the browser.
554 If a fully-qualified URL is specified (that is, including
555 <code>http://servername/</code>) then a redirect will be issued to that
556 location. Otherwise, the current protocol, servername, and port number
557 will be used to generate the URL sent with the redirect.
558 </p>
559
560 <p>
561 <em>Any</em> valid HTTP response  status code may be specified, 
562 using the syntax [R=305], with a 302 status code being used by 
563 default if none is specified. The status code specified need not
564 necessarily be a redirect (3xx) status code.
565 </p>
566
567 <p>If a status code is outside the redirect range (300-399) then the
568 substitution string is dropped entirely, and rewriting is stopped as if
569 the <code>L</code> were used.</p>
570
571 <p>In addition to response status codes, you may also specify redirect
572 status using their symbolic names: <code>temp</code> (default), 
573 <code>permanent</code>, or <code>seeother</code>.</p>
574
575 <p>
576 You will almost always want to use [R] in conjunction with [L] (that is,
577 use [R,L]) because on its own, the [R] flag prepends
578 <code>http://thishost[:thisport]</code> to the URI, but then passes this
579 on to the next rule in the ruleset, which can often result in 'Invalid
580 URI in request' warnings.
581 </p>
582
583 </section>
584
585 <section id="flag_s"><title>S|skip</title>
586 <p>The [S] flag is used to skip rules that you don't want to run. This
587 can be thought of as a <code>goto</code> statement in your rewrite
588 ruleset. In the following example, we only want to run the <directive
589 module="mod_rewrite">RewriteRule</directive> if the requested URI
590 doesn't correspond with an actual file.</p>
591
592 <example>
593 # Is the request for a non-existent file?<br />
594 RewriteCond %{REQUEST_FILENAME} !-f<br />
595 RewriteCond %{REQUEST_FILENAME} !-d<br />
596 # If so, skip these two RewriteRules<br />
597 RewriteRule .? - [S=2]<br />
598 <br />
599 RewriteRule (.*\.gif) images.php?$1<br />
600 RewriteRule (.*\.html) docs.php?$1
601 </example>
602
603 <p>This technique is useful because a <directive
604 module="mod_rewrite">RewriteCond</directive> only applies to the
605 <directive module="mod_rewrite">RewriteRule</directive> immediately
606 following it. Thus, if you want to make a <code>RewriteCond</code> apply
607 to several <code>RewriteRule</code>s, one possible technique is to
608 negate those conditions and use a [Skip] flag. So, you can 
609 use this to make pseudo if-then-else constructs: The last rule of 
610 the then-clause becomes <code>skip=N</code>, where N is the 
611 number of rules in the else-clause.</p>
612 </section>
613
614 <section id="flag_t"><title>T|type</title>
615 <p>Sets the MIME type with which the resulting response will be
616 sent. This has the same effect as the <directive
617 module="mod_mime">AddType</directive> directive.</p>
618
619 <p>For example, you might use the following technique to serve Perl
620 source code as plain text, if requested in a particular way:</p>
621
622 <example>
623 # Serve .pl files as plain text<br />
624 RewriteRule \.pl$ - [T=text/plain]
625 </example>
626
627 <p>Or, perhaps, if you have a camera that produces jpeg images without
628 file extensions, you could force those images to be served with the
629 correct MIME type by virtue of their file names:</p>
630
631 <example>
632 # Files with 'IMG' in the name are jpg images.<br />
633 RewriteRule IMG - [T=image/jpg]
634 </example>
635
636 <p>Please note that this is a trivial example, and could be better done
637 using <directive type="section" module="core">FilesMatch</directive>
638 instead. Always consider the alternate
639 solutions to a problem before resorting to rewrite, which will
640 invariably be a less efficient solution than the alternatives.</p>
641
642 <p>
643 If used in per-directory context, use only <code>-</code> (dash)
644 as the substitution <em>for the entire round of mod_rewrite processing</em>, 
645 otherwise the MIME-type set with this flag is lost due to an internal 
646 re-processing (including subsequent rounds of mod_rewrite processing).
647 The <code>L</code> flag can be useful in this context to end the 
648 <em>current</em> round of mod_rewrite processing.</p>
649
650 </section>
651
652 </manualpage>
653