Mercurial > hg > nginx-site
annotate xml/en/docs/http/ngx_http_rewrite_module.xml @ 2809:e642fe346261
Added note about requests distribution to sticky cookie.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 30 Nov 2021 11:49:59 +0000 |
parents | dd78dd9e2cb7 |
children |
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 | 12 lang="en" |
2057
dd78dd9e2cb7
Corrected directive processing order in the rewrite module.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
1964
diff
changeset
|
13 rev="9"> |
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 | 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> |
2057
dd78dd9e2cb7
Corrected directive processing order in the rewrite module.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
1964
diff
changeset
|
24 The <link id="break"/>, <link id="if"/>, <link id="return"/>, |
dd78dd9e2cb7
Corrected directive processing order in the rewrite module.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
1964
diff
changeset
|
25 <link id="rewrite"/>, and <link id="set"/> directives are |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
26 processed in the following order: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
27 <list type="bullet"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
28 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
29 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
30 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
|
31 <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
|
32 are executed sequentially; |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
33 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
34 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
35 <listitem> |
1061
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
36 repeatedly: |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
37 <list type="bullet"> |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
38 |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
39 <listitem> |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
40 a |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
41 <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
|
42 is searched based on a request URI; |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
43 </listitem> |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
44 |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
45 <listitem> |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
46 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
|
47 are executed sequentially; |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
48 </listitem> |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
49 |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
50 <listitem> |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
51 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
|
52 but not more than |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
53 <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
|
54 </listitem> |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
55 |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
56 </list> |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
57 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
58 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
59 </list> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
60 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
61 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
62 </section> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
65 <section id="directives" name="Directives"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
66 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
67 <directive name="break"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
68 <syntax/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
69 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
70 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
71 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
72 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
73 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
74 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
75 Stops processing the current set of |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
76 <literal>ngx_http_rewrite_module</literal> directives. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
77 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
78 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
79 <para> |
1061
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
80 If a directive is specified inside the |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
81 <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
|
82 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
|
83 </para> |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
84 |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
85 <para> |
392
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 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
88 if ($slow) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
89 limit_rate 10k; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
90 break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
91 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
92 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
93 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
94 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
95 </directive> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
98 <directive name="if"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
99 <syntax block="yes">(<value>condition</value>)</syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
100 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
101 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
102 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
103 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
104 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
105 The specified <value>condition</value> is evaluated. |
966 | 106 If true, this module directives specified inside the braces are |
107 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
|
108 <literal>if</literal> directive. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
109 Configurations inside the <literal>if</literal> directives are |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
110 inherited from the previous configuration level. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
111 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
112 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
113 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
114 A condition may be any of the following: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
115 <list type="bullet"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
116 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
117 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
118 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
|
119 or “<literal>0</literal>”; |
9fce700e56d3
If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents:
702
diff
changeset
|
120 <note> |
9fce700e56d3
If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents:
702
diff
changeset
|
121 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
|
122 was considered a false value. |
9fce700e56d3
If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents:
702
diff
changeset
|
123 </note> |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
124 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
125 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
126 <listitem> |
966 | 127 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
|
128 “<literal>=</literal>” and “<literal>!=</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
129 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
130 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
131 <listitem> |
966 | 132 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
|
133 “<literal>~</literal>” (for case-sensitive matching) and |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
134 “<literal>~*</literal>” (for case-insensitive matching) operators. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
135 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
|
136 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
|
137 Negative operators “<literal>!~</literal>” and “<literal>!~*</literal>” |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
138 are also available. |
966 | 139 If a regular expression includes the “<literal>}</literal>” |
140 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
|
141 in single or double quotes. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
142 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
143 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
144 <listitem> |
966 | 145 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
|
146 “<literal>!-f</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
147 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
148 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
149 <listitem> |
966 | 150 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
|
151 “<literal>!-d</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
152 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
153 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
154 <listitem> |
966 | 155 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
|
156 “<literal>-e</literal>” and “<literal>!-e</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
157 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
158 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
159 <listitem> |
966 | 160 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
|
161 and “<literal>!-x</literal>” operators. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
162 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
163 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
164 </list> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
165 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
166 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
167 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
168 Examples: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
169 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
170 if ($http_user_agent ~ MSIE) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
171 rewrite ^(.*)$ /msie/$1 break; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
174 if ($http_cookie ~* "id=([^;]+)(?:;|$)") { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
175 set $id $1; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
178 if ($request_method = POST) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
179 return 405; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
182 if ($slow) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
183 limit_rate 10k; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
186 if ($invalid_referer) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
187 return 403; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
188 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
189 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
190 <note> |
966 | 191 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
|
192 <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
|
193 </note> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
194 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
195 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
196 </directive> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
199 <directive name="return"> |
548
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
200 <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
|
201 <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
|
202 <syntax><value>URL</value></syntax> |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
203 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
204 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
205 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
206 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
207 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
208 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
209 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
|
210 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
|
211 a response header. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
212 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
213 |
548
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
214 <para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
215 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
|
216 either a redirect URL (for codes 301, 302, 303, 307, and 308) |
966 | 217 or the response body <value>text</value> (for other codes). |
218 A response body text and redirect URL can contain variables. | |
219 As a special case, a redirect URL can be specified as a URI | |
220 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
|
221 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
|
222 <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
|
223 <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
|
224 </para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
225 |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
226 <para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
227 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
|
228 can be specified as the sole parameter. |
966 | 229 Such a parameter should start with the “<literal>http://</literal>”, |
230 “<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
|
231 A <value>URL</value> can contain variables. |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
232 </para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
233 |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
234 <para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
235 <note> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
236 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
|
237 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
|
238 </note> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
239 |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
240 <note> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
241 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
|
242 </note> |
1964
2a3c58dcb3e8
Documented support for the 308 Permanent Redirect.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
1873
diff
changeset
|
243 |
2a3c58dcb3e8
Documented support for the 308 Permanent Redirect.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
1873
diff
changeset
|
244 <note> |
2a3c58dcb3e8
Documented support for the 308 Permanent Redirect.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
1873
diff
changeset
|
245 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
|
246 </note> |
548
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
247 </para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
248 |
1061
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
249 <para> |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
250 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
|
251 </para> |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
252 |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
253 </directive> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
256 <directive name="rewrite"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
257 <syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
258 <value>regex</value> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
259 <value>replacement</value> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
260 [<value>flag</value>]</syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
261 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
262 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
263 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
264 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
265 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
266 <para> |
1061
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
267 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
|
268 as specified in the <value>replacement</value> string. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
269 The <literal>rewrite</literal> directives are executed sequentially |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
270 in order of their appearance in the configuration file. |
966 | 271 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
|
272 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
|
273 “<literal>https://</literal>”, or “<literal>$scheme</literal>”, |
2f851f71ff08
Documented $scheme support in the "rewrite" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
1723
diff
changeset
|
274 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
|
275 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
276 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
277 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
278 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
|
279 <list type="tag"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
280 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
281 <tag-name><literal>last</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
282 <tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
283 stops processing the current set of |
966 | 284 <literal>ngx_http_rewrite_module</literal> directives and starts |
285 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
|
286 </tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
287 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
288 <tag-name><literal>break</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
289 <tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
290 stops processing the current set of |
1061
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
291 <literal>ngx_http_rewrite_module</literal> directives |
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
292 as with the <link id="break"/> directive; |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
293 </tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
294 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
295 <tag-name><literal>redirect</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
296 <tag-desc> |
966 | 297 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
|
298 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
|
299 “<literal>http://</literal>”, “<literal>https://</literal>”, |
2f851f71ff08
Documented $scheme support in the "rewrite" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
1723
diff
changeset
|
300 or “<literal>$scheme</literal>”; |
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 <tag-name><literal>permanent</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
304 <tag-desc> |
966 | 305 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
|
306 </tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
307 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
308 </list> |
966 | 309 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
|
310 request scheme (<var>$scheme</var>) and the |
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="server_name_in_redirect"/> and |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
312 <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
|
313 </para> |
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 <para> |
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 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
318 server { |
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 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
321 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
322 return 403; |
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 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
325 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
326 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
327 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
328 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
329 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
|
330 location, the <literal>last</literal> flag should be replaced by |
966 | 331 <literal>break</literal>, or otherwise nginx will make 10 cycles and |
332 return the 500 error: | |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
333 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
334 location /download/ { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
335 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
336 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
337 return 403; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
338 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
339 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
340 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
341 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
342 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
343 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
|
344 the previous request arguments are appended after them. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
345 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
|
346 string avoids having them appended, for example: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
347 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
348 rewrite ^/users/(.*)$ /show?user=$1? last; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
349 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
350 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
351 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
352 <para> |
966 | 353 If a regular expression includes the “<literal>}</literal>” |
354 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
|
355 in single or double quotes. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
356 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
357 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
358 </directive> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
359 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
360 |
673
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
361 <directive name="rewrite_log"> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
362 <syntax><literal>on</literal> | <literal>off</literal></syntax> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
363 <default>off</default> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
364 <context>http</context> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
365 <context>server</context> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
366 <context>location</context> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
367 <context>if</context> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
368 |
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 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
|
371 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
|
372 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
|
373 the <literal>notice</literal> level. |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
374 </para> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
375 |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
376 </directive> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
377 |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
378 |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
379 <directive name="set"> |
1061
cb63563024eb
Somewhat clarified how rewrite module works.
Ruslan Ermilov <ru@nginx.com>
parents:
966
diff
changeset
|
380 <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
|
381 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
382 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
383 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
384 <context>if</context> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
387 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
|
388 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
|
389 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
390 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
391 </directive> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
394 <directive name="uninitialized_variable_warn"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
395 <syntax><literal>on</literal> | <literal>off</literal></syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
396 <default>on</default> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
397 <context>http</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
398 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
399 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
400 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
401 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
402 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
403 Controls whether warnings about uninitialized variables are logged. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
404 </para> |
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 </directive> |
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 </section> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
411 <section id="internals" name="Internal Implementation"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
412 |
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 The <literal>ngx_http_rewrite_module</literal> module directives |
966 | 415 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
|
416 that are interpreted during request processing. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
417 An interpreter is a simple virtual stack machine. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
418 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
419 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
420 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
421 For example, the directives |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
422 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
423 location /download/ { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
424 if ($forbidden) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
425 return 403; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
428 if ($slow) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
429 limit_rate 10k; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
432 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
433 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
434 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
435 will be translated into these instructions: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
436 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
437 variable $forbidden |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
438 check against zero |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
439 return 403 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
440 end of code |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
441 variable $slow |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
442 check against zero |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
443 match of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
444 copy "/" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
445 copy $1 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
446 copy "/mp3/" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
447 copy $2 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
448 copy ".mp3" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
449 end of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
450 end of code |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
451 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
452 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
453 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
454 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
455 Note that there are no instructions for the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
456 <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
|
457 directive above as it is unrelated to the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
458 <literal>ngx_http_rewrite_module</literal> module. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
459 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
|
460 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
|
461 where <literal>limit_rate</literal> equals to 10k. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
462 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
463 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
464 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
465 The directive |
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 ^/(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 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
|
470 is put inside the parentheses: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
471 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
472 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
|
473 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
474 The corresponding instructions will then look like this: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
475 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
476 match of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
477 copy $1 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
478 copy "/mp3/" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
479 copy $2 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
480 copy ".mp3" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
481 end of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
482 end of code |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
483 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
484 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
485 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
486 </section> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
487 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
488 </module> |