annotate xml/en/docs/http/ngx_http_rewrite_module.xml @ 1964:2a3c58dcb3e8

Documented support for the 308 Permanent Redirect.
author Yaroslav Zhuravlev <yar@nginx.com>
date Mon, 17 Apr 2017 19:29:14 +0300
parents 2f851f71ff08
children dd78dd9e2cb7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1 <?xml version="1.0"?>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
2
580
be54c443235a Added copyright markers to documentation sources.
Ruslan Ermilov <ru@nginx.com>
parents: 548
diff changeset
3 <!--
be54c443235a Added copyright markers to documentation sources.
Ruslan Ermilov <ru@nginx.com>
parents: 548
diff changeset
4 Copyright (C) Igor Sysoev
be54c443235a Added copyright markers to documentation sources.
Ruslan Ermilov <ru@nginx.com>
parents: 548
diff changeset
5 Copyright (C) Nginx, Inc.
be54c443235a Added copyright markers to documentation sources.
Ruslan Ermilov <ru@nginx.com>
parents: 548
diff changeset
6 -->
be54c443235a Added copyright markers to documentation sources.
Ruslan Ermilov <ru@nginx.com>
parents: 548
diff changeset
7
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
8 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
9
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
10 <module name="Module ngx_http_rewrite_module"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
11 link="/en/docs/http/ngx_http_rewrite_module.html"
589
764fbac1b8b4 Added document revision.
Ruslan Ermilov <ru@nginx.com>
parents: 580
diff changeset
12 lang="en"
1964
2a3c58dcb3e8 Documented support for the 308 Permanent Redirect.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1873
diff changeset
13 rev="8">
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
14
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
15 <section id="summary">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
16
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
17 <para>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
18 The <literal>ngx_http_rewrite_module</literal> module is used to
1723
065978f4ece1 Added info about PCRE in the rewrite module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1151
diff changeset
19 change request URI using PCRE regular expressions, return redirects, and
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
20 conditionally select configurations.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
21 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
22
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
23 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
24 The <literal>ngx_http_rewrite_module</literal> module directives are
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
25 processed in the following order:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
26 <list type="bullet">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
27
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
28 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
29 the directives of this module specified on the
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
30 <link doc="ngx_http_core_module.xml" id="server"/> level
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
31 are executed sequentially;
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
32 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
33
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
34 <listitem>
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
35 repeatedly:
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
36 <list type="bullet">
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
37
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
38 <listitem>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
39 a
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
40 <link doc="ngx_http_core_module.xml" id="location"/>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
41 is searched based on a request URI;
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
42 </listitem>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
43
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
44 <listitem>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
45 the directives of this module specified inside the found location
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
46 are executed sequentially;
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
47 </listitem>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
48
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
49 <listitem>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
50 the loop is repeated if a request URI was <link id="rewrite">rewritten</link>,
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
51 but not more than
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
52 <link doc="ngx_http_core_module.xml" id="internal">10 times</link>.
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
53 </listitem>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
54
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
55 </list>
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
56 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
57
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
58 </list>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
59 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
60
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
61 </section>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
62
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
63
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
64 <section id="directives" name="Directives">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
65
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
66 <directive name="break">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
67 <syntax/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
68 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
69 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
70 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
71 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
72
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
73 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
74 Stops processing the current set of
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
75 <literal>ngx_http_rewrite_module</literal> directives.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
76 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
77
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
78 <para>
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
79 If a directive is specified inside the
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
80 <link doc="ngx_http_core_module.xml" id="location"/>,
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
81 further processing of the request continues in this location.
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
82 </para>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
83
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
84 <para>
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
85 Example:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
86 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
87 if ($slow) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
88 limit_rate 10k;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
89 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
90 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
91 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
92 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
93
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
94 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
95
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
96
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
97 <directive name="if">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
98 <syntax block="yes">(<value>condition</value>)</syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
99 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
100 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
101 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
102
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
103 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
104 The specified <value>condition</value> is evaluated.
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
105 If true, this module directives specified inside the braces are
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
106 executed, and the request is assigned the configuration inside the
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
107 <literal>if</literal> directive.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
108 Configurations inside the <literal>if</literal> directives are
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
109 inherited from the previous configuration level.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
110 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
111
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
112 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
113 A condition may be any of the following:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
114 <list type="bullet">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
115
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
116 <listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
117 a variable name; false if the value of a variable is an empty string
860
9fce700e56d3 If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents: 702
diff changeset
118 or “<literal>0</literal>”;
9fce700e56d3 If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents: 702
diff changeset
119 <note>
9fce700e56d3 If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents: 702
diff changeset
120 Before version 1.0.1, any string starting with “<literal>0</literal>”
9fce700e56d3 If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents: 702
diff changeset
121 was considered a false value.
9fce700e56d3 If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents: 702
diff changeset
122 </note>
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
123 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
124
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
125 <listitem>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
126 comparison of a variable with a string using the
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
127 “<literal>=</literal>” and “<literal>!=</literal>” operators;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
128 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
129
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
130 <listitem>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
131 matching of a variable against a regular expression using the
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
132 “<literal>~</literal>” (for case-sensitive matching) and
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
133 “<literal>~*</literal>” (for case-insensitive matching) operators.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
134 Regular expressions can contain captures that are made available for
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
135 later reuse in the <var>$1</var>..<var>$9</var> variables.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
136 Negative operators “<literal>!~</literal>” and “<literal>!~*</literal>”
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
137 are also available.
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
138 If a regular expression includes the “<literal>}</literal>”
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
139 or “<literal>;</literal>” characters, the whole expressions should be enclosed
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
140 in single or double quotes.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
141 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
142
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
143 <listitem>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
144 checking of a file existence with the “<literal>-f</literal>” and
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
145 “<literal>!-f</literal>” operators;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
146 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
147
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
148 <listitem>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
149 checking of a directory existence with the “<literal>-d</literal>” and
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
150 “<literal>!-d</literal>” operators;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
151 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
152
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
153 <listitem>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
154 checking of a file, directory, or symbolic link existence with the
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
155 “<literal>-e</literal>” and “<literal>!-e</literal>” operators;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
156 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
157
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
158 <listitem>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
159 checking for an executable file with the “<literal>-x</literal>”
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
160 and “<literal>!-x</literal>” operators.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
161 </listitem>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
162
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
163 </list>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
164 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
165
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
166 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
167 Examples:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
168 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
169 if ($http_user_agent ~ MSIE) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
170 rewrite ^(.*)$ /msie/$1 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
171 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
172
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
173 if ($http_cookie ~* "id=([^;]+)(?:;|$)") {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
174 set $id $1;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
175 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
176
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
177 if ($request_method = POST) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
178 return 405;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
179 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
180
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
181 if ($slow) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
182 limit_rate 10k;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
183 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
184
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
185 if ($invalid_referer) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
186 return 403;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
187 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
188 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
189 <note>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
190 A value of the <var>$invalid_referer</var> embedded variable is set by the
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
191 <link doc="ngx_http_referer_module.xml" id="valid_referers"/> directive.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
192 </note>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
193 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
194
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
195 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
196
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
197
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
198 <directive name="return">
548
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
199 <syntax><value>code</value> [<value>text</value>]</syntax>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
200 <syntax><value>code</value> <value>URL</value></syntax>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
201 <syntax><value>URL</value></syntax>
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
202 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
203 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
204 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
205 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
206
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
207 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
208 Stops processing and returns the specified <value>code</value> to a client.
548
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
209 The non-standard code 444 closes a connection without sending
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
210 a response header.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
211 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
212
548
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
213 <para>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
214 Starting from version 0.8.42, it is possible to specify
1964
2a3c58dcb3e8 Documented support for the 308 Permanent Redirect.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1873
diff changeset
215 either a redirect URL (for codes 301, 302, 303, 307, and 308)
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
216 or the response body <value>text</value> (for other codes).
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
217 A response body text and redirect URL can contain variables.
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
218 As a special case, a redirect URL can be specified as a URI
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
219 local to this server, in which case the full redirect URL
548
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
220 is formed according to the request scheme (<var>$scheme</var>) and the
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
221 <link doc="ngx_http_core_module.xml" id="server_name_in_redirect"/> and
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
222 <link doc="ngx_http_core_module.xml" id="port_in_redirect"/> directives.
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
223 </para>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
224
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
225 <para>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
226 In addition, a <value>URL</value> for temporary redirect with the code 302
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
227 can be specified as the sole parameter.
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
228 Such a parameter should start with the “<literal>http://</literal>”,
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
229 “<literal>https://</literal>”, or “<literal>$scheme</literal>” string.
548
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
230 A <value>URL</value> can contain variables.
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
231 </para>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
232
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
233 <para>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
234 <note>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
235 Only the following codes could be returned before version 0.7.51:
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
236 204, 400, 402 — 406, 408, 410, 411, 413, 416, and 500 — 504.
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
237 </note>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
238
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
239 <note>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
240 The code 307 was not treated as a redirect until versions 1.1.16 and 1.0.13.
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
241 </note>
1964
2a3c58dcb3e8 Documented support for the 308 Permanent Redirect.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1873
diff changeset
242
2a3c58dcb3e8 Documented support for the 308 Permanent Redirect.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1873
diff changeset
243 <note>
2a3c58dcb3e8 Documented support for the 308 Permanent Redirect.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1873
diff changeset
244 The code 308 was not treated as a redirect until version 1.13.0.
2a3c58dcb3e8 Documented support for the 308 Permanent Redirect.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1873
diff changeset
245 </note>
548
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
246 </para>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
247
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
248 <para>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
249 See also the <link doc="ngx_http_core_module.xml" id="error_page"/> directive.
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
250 </para>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
251
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
252 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
253
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
254
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
255 <directive name="rewrite">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
256 <syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
257 <value>regex</value>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
258 <value>replacement</value>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
259 [<value>flag</value>]</syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
260 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
261 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
262 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
263 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
264
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
265 <para>
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
266 If the specified regular expression matches a request URI, URI is changed
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
267 as specified in the <value>replacement</value> string.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
268 The <literal>rewrite</literal> directives are executed sequentially
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
269 in order of their appearance in the configuration file.
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
270 It is possible to terminate further processing of the directives using flags.
1873
2f851f71ff08 Documented $scheme support in the "rewrite" directive.
Ruslan Ermilov <ru@nginx.com>
parents: 1723
diff changeset
271 If a replacement string starts with “<literal>http://</literal>”,
2f851f71ff08 Documented $scheme support in the "rewrite" directive.
Ruslan Ermilov <ru@nginx.com>
parents: 1723
diff changeset
272 “<literal>https://</literal>”, or “<literal>$scheme</literal>”,
2f851f71ff08 Documented $scheme support in the "rewrite" directive.
Ruslan Ermilov <ru@nginx.com>
parents: 1723
diff changeset
273 the processing stops and the redirect is returned to a client.
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
274 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
275
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
276 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
277 An optional <value>flag</value> parameter can be one of:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
278 <list type="tag">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
279
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
280 <tag-name><literal>last</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
281 <tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
282 stops processing the current set of
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
283 <literal>ngx_http_rewrite_module</literal> directives and starts
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
284 a search for a new location matching the changed URI;
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
285 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
286
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
287 <tag-name><literal>break</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
288 <tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
289 stops processing the current set of
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
290 <literal>ngx_http_rewrite_module</literal> directives
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
291 as with the <link id="break"/> directive;
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
292 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
293
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
294 <tag-name><literal>redirect</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
295 <tag-desc>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
296 returns a temporary redirect with the 302 code;
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
297 used if a replacement string does not start with
1873
2f851f71ff08 Documented $scheme support in the "rewrite" directive.
Ruslan Ermilov <ru@nginx.com>
parents: 1723
diff changeset
298 “<literal>http://</literal>”, “<literal>https://</literal>”,
2f851f71ff08 Documented $scheme support in the "rewrite" directive.
Ruslan Ermilov <ru@nginx.com>
parents: 1723
diff changeset
299 or “<literal>$scheme</literal>”;
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
300 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
301
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
302 <tag-name><literal>permanent</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
303 <tag-desc>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
304 returns a permanent redirect with the 301 code.
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
305 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
306
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
307 </list>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
308 The full redirect URL is formed according to the
548
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
309 request scheme (<var>$scheme</var>) and the
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
310 <link doc="ngx_http_core_module.xml" id="server_name_in_redirect"/> and
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
311 <link doc="ngx_http_core_module.xml" id="port_in_redirect"/> directives.
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
312 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
313
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
314 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
315 Example:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
316 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
317 server {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
318 ...
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
319 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
320 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
321 return 403;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
322 ...
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
323 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
324 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
325 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
326
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
327 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
328 But if these directives are put inside the “<literal>/download/</literal>”
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
329 location, the <literal>last</literal> flag should be replaced by
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
330 <literal>break</literal>, or otherwise nginx will make 10 cycles and
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
331 return the 500 error:
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
332 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
333 location /download/ {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
334 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
335 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
336 return 403;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
337 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
338 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
339 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
340
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
341 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
342 If a <value>replacement</value> string includes the new request arguments,
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
343 the previous request arguments are appended after them.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
344 If this is undesired, putting a question mark at the end of a replacement
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
345 string avoids having them appended, for example:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
346 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
347 rewrite ^/users/(.*)$ /show?user=$1? last;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
348 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
349 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
350
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
351 <para>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
352 If a regular expression includes the “<literal>}</literal>”
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
353 or “<literal>;</literal>” characters, the whole expressions should be enclosed
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
354 in single or double quotes.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
355 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
356
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
357 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
358
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
359
673
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
360 <directive name="rewrite_log">
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
361 <syntax><literal>on</literal> | <literal>off</literal></syntax>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
362 <default>off</default>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
363 <context>http</context>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
364 <context>server</context>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
365 <context>location</context>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
366 <context>if</context>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
367
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
368 <para>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
369 Enables or disables logging of <literal>ngx_http_rewrite_module</literal>
702
6b6585577c33 Slightly changed the wording when talking about the "rewrite_log" directive.
Ruslan Ermilov <ru@nginx.com>
parents: 674
diff changeset
370 module directives processing results
6b6585577c33 Slightly changed the wording when talking about the "rewrite_log" directive.
Ruslan Ermilov <ru@nginx.com>
parents: 674
diff changeset
371 into the <link doc="../ngx_core_module.xml" id="error_log"/> at
673
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
372 the <literal>notice</literal> level.
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
373 </para>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
374
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
375 </directive>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
376
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
377
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
378 <directive name="set">
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
379 <syntax><value>$variable</value> <value>value</value></syntax>
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
380 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
381 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
382 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
383 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
384
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
385 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
386 Sets a <value>value</value> for the specified <value>variable</value>.
1151
4c2324a7eeea Corrected the usage of articles and a comma.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1061
diff changeset
387 The <value>value</value> can contain text, variables, and their combination.
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
388 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
389
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
390 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
391
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
393 <directive name="uninitialized_variable_warn">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
394 <syntax><literal>on</literal> | <literal>off</literal></syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
395 <default>on</default>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
396 <context>http</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
397 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
398 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
399 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
400
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
401 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
402 Controls whether warnings about uninitialized variables are logged.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
403 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
404
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
405 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
406
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
407 </section>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
408
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
409
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
410 <section id="internals" name="Internal Implementation">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
411
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
412 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
413 The <literal>ngx_http_rewrite_module</literal> module directives
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
414 are compiled at the configuration stage into internal instructions
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
415 that are interpreted during request processing.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
416 An interpreter is a simple virtual stack machine.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
417 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
418
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
419 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
420 For example, the directives
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
421 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
422 location /download/ {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
423 if ($forbidden) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
424 return 403;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
425 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
426
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
427 if ($slow) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
428 limit_rate 10k;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
429 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
430
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
431 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
432 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
433 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
434 will be translated into these instructions:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
435 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
436 variable $forbidden
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
437 check against zero
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
438 return 403
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
439 end of code
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
440 variable $slow
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
441 check against zero
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
442 match of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
443 copy "/"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
444 copy $1
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
445 copy "/mp3/"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
446 copy $2
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
447 copy ".mp3"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
448 end of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
449 end of code
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
450 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
451 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
452
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
453 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
454 Note that there are no instructions for the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
455 <link doc="ngx_http_core_module.xml" id="limit_rate"/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
456 directive above as it is unrelated to the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
457 <literal>ngx_http_rewrite_module</literal> module.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
458 A separate configuration is created for the <link id="if"/> block.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
459 If the condition holds true, a request is assigned this configuration
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
460 where <literal>limit_rate</literal> equals to 10k.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
461 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
462
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
463 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
464 The directive
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
465 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
466 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
467 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
468 can be made smaller by one instruction if the first slash in the regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
469 is put inside the parentheses:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
470 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
471 rewrite ^(<emphasis>/</emphasis>download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
472 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
473 The corresponding instructions will then look like this:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
474 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
475 match of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
476 copy $1
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
477 copy "/mp3/"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
478 copy $2
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
479 copy ".mp3"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
480 end of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
481 end of code
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
482 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
483 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
484
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
485 </section>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
486
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
487 </module>