annotate xml/en/docs/http/ngx_http_rewrite_module.xml @ 1878:127ae107e5a9

Removed clause about shared memory and Windows versions with ASLR. Starting with nginx 1.9.0 shared memory can be used on Windows versions with address space layout randomization.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 26 Dec 2016 19:38:06 +0300
parents 2f851f71ff08
children 2a3c58dcb3e8
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"
1873
2f851f71ff08 Documented $scheme support in the "rewrite" directive.
Ruslan Ermilov <ru@nginx.com>
parents: 1723
diff changeset
13 rev="7">
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
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
215 either a redirect URL (for codes 301, 302, 303, and 307),
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>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
242 </para>
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
243
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
244 <para>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
245 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
246 </para>
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
247
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
248 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
249
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
250
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
251 <directive name="rewrite">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
252 <syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
253 <value>regex</value>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
254 <value>replacement</value>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
255 [<value>flag</value>]</syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
256 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
257 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
258 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
259 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
260
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
261 <para>
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
262 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
263 as specified in the <value>replacement</value> string.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
264 The <literal>rewrite</literal> directives are executed sequentially
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
265 in order of their appearance in the configuration file.
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
266 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
267 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
268 “<literal>https://</literal>”, or “<literal>$scheme</literal>”,
2f851f71ff08 Documented $scheme support in the "rewrite" directive.
Ruslan Ermilov <ru@nginx.com>
parents: 1723
diff changeset
269 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
270 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
271
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
272 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
273 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
274 <list type="tag">
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 <tag-name><literal>last</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
277 <tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
278 stops processing the current set of
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
279 <literal>ngx_http_rewrite_module</literal> directives and starts
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
280 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
281 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
282
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
283 <tag-name><literal>break</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
284 <tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
285 stops processing the current set of
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
286 <literal>ngx_http_rewrite_module</literal> directives
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
287 as with the <link id="break"/> directive;
392
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
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
290 <tag-name><literal>redirect</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
291 <tag-desc>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
292 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
293 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
294 “<literal>http://</literal>”, “<literal>https://</literal>”,
2f851f71ff08 Documented $scheme support in the "rewrite" directive.
Ruslan Ermilov <ru@nginx.com>
parents: 1723
diff changeset
295 or “<literal>$scheme</literal>”;
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
296 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
297
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
298 <tag-name><literal>permanent</literal></tag-name>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
299 <tag-desc>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
300 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
301 </tag-desc>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
302
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
303 </list>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
304 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
305 request scheme (<var>$scheme</var>) and the
95a970603b0f Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents: 402
diff changeset
306 <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
307 <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
308 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
309
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
310 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
311 Example:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
312 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
313 server {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
314 ...
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
315 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
316 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
317 return 403;
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 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
320 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
321 </para>
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 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
324 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
325 location, the <literal>last</literal> flag should be replaced by
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
326 <literal>break</literal>, or otherwise nginx will make 10 cycles and
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
327 return the 500 error:
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
328 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
329 location /download/ {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
330 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
331 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
332 return 403;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
333 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
334 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
335 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
336
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
337 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
338 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
339 the previous request arguments are appended after them.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
340 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
341 string avoids having them appended, for example:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
342 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
343 rewrite ^/users/(.*)$ /show?user=$1? last;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
344 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
345 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
346
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
347 <para>
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
348 If a regular expression includes the “<literal>}</literal>”
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
349 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
350 in single or double quotes.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
351 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
352
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
353 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
354
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
355
673
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
356 <directive name="rewrite_log">
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
357 <syntax><literal>on</literal> | <literal>off</literal></syntax>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
358 <default>off</default>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
359 <context>http</context>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
360 <context>server</context>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
361 <context>location</context>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
362 <context>if</context>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
363
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
364 <para>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
365 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
366 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
367 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
368 the <literal>notice</literal> level.
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
369 </para>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
370
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
371 </directive>
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
372
f2d8603813b0 Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents: 589
diff changeset
373
392
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
374 <directive name="set">
1061
cb63563024eb Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents: 966
diff changeset
375 <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
376 <default/>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
377 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
378 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
379 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
380
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
381 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
382 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
383 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
384 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
385
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
386 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
387
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
388
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
389 <directive name="uninitialized_variable_warn">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
390 <syntax><literal>on</literal> | <literal>off</literal></syntax>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
391 <default>on</default>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
392 <context>http</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
393 <context>server</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
394 <context>location</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
395 <context>if</context>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
396
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
397 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
398 Controls whether warnings about uninitialized variables are logged.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
399 </para>
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 </directive>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
402
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
403 </section>
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
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
406 <section id="internals" name="Internal Implementation">
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
407
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
408 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
409 The <literal>ngx_http_rewrite_module</literal> module directives
966
95c3c3bbf1ce Text review.
Egor Nikitin <yegor.nikitin@gmail.com>
parents: 934
diff changeset
410 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
411 that are interpreted during request processing.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
412 An interpreter is a simple virtual stack machine.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
413 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
414
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
415 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
416 For example, the directives
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
417 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
418 location /download/ {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
419 if ($forbidden) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
420 return 403;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
421 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
422
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
423 if ($slow) {
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
424 limit_rate 10k;
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 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
428 }
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
429 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
430 will be translated into these instructions:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
431 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
432 variable $forbidden
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
433 check against zero
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
434 return 403
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
435 end of code
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
436 variable $slow
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 match of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
439 copy "/"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
440 copy $1
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
441 copy "/mp3/"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
442 copy $2
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
443 copy ".mp3"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
444 end of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
445 end of code
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
446 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
447 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
448
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
449 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
450 Note that there are no instructions for the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
451 <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
452 directive above as it is unrelated to the
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
453 <literal>ngx_http_rewrite_module</literal> module.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
454 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
455 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
456 where <literal>limit_rate</literal> equals to 10k.
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
457 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
458
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
459 <para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
460 The directive
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
461 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
462 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break;
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
463 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
464 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
465 is put inside the parentheses:
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
466 <example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
467 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
468 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
469 The corresponding instructions will then look like this:
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 match of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
472 copy $1
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
473 copy "/mp3/"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
474 copy $2
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
475 copy ".mp3"
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
476 end of regular expression
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
477 end of code
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
478 </example>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
479 </para>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
480
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
481 </section>
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
482
5fd99d37a3e6 English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
483 </module>