Mercurial > hg > nginx-site
annotate xml/en/docs/http/ngx_http_rewrite_module.xml @ 860:9fce700e56d3
If: only empty strings and "0" evaluate to false.
Before version 1.0.1, any string starting with "0" was considered
a false value.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Thu, 07 Mar 2013 08:11:34 +0400 |
parents | 6b6585577c33 |
children | 9b549f369a36 |
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" |
860
9fce700e56d3
If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents:
702
diff
changeset
|
13 rev="4"> |
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> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
18 The <literal>ngx_http_rewrite_module</literal> module allows to |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
19 change URIs using regular expressions, return redirects, and |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
30 <link doc="ngx_http_core_module.xml" id="server"/> level are processed; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
31 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
32 |
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 a location for a request is searched; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
35 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
36 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
37 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
38 the directives of this module specified in the selected |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
39 <link doc="ngx_http_core_module.xml" id="location"/> are processed, |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
40 and if they changed a URI, a new location is searched for the new URI. |
674
c48c0936b4df
Documented internal redirections limit.
Vladimir Homutov <vl@nginx.com>
parents:
673
diff
changeset
|
41 This cycle may be repeated up to |
c48c0936b4df
Documented internal redirections limit.
Vladimir Homutov <vl@nginx.com>
parents:
673
diff
changeset
|
42 <link doc="ngx_http_core_module.xml" id="internal">10 times</link> |
c48c0936b4df
Documented internal redirections limit.
Vladimir Homutov <vl@nginx.com>
parents:
673
diff
changeset
|
43 after which the error <http-status code="500" text="Internal Server Error"/> |
c48c0936b4df
Documented internal redirections limit.
Vladimir Homutov <vl@nginx.com>
parents:
673
diff
changeset
|
44 is returned. |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
45 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
46 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
47 </list> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
48 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
49 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
50 </section> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
51 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
52 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
53 <section id="directives" name="Directives"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
54 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
55 <directive name="break"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
56 <syntax/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
57 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
58 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
59 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
60 <context>if</context> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
63 Stops processing the current set of |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
64 <literal>ngx_http_rewrite_module</literal> directives. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
65 </para> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
68 Example: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
69 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
70 if ($slow) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
71 limit_rate 10k; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
72 break; |
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 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
75 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
76 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
77 </directive> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
80 <directive name="if"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
81 <syntax block="yes">(<value>condition</value>)</syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
82 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
83 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
84 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
85 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
86 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
87 The specified <value>condition</value> is evaluated. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
88 If true, the directives of this module specified inside the braces are |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
89 executed, and a request is assigned the configuration inside the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
90 <literal>if</literal> directive. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
91 Configurations inside the <literal>if</literal> directives are |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
92 inherited from the previous configuration level. |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
96 A condition may be any of the following: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
97 <list type="bullet"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
98 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
99 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
100 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
|
101 or “<literal>0</literal>”; |
9fce700e56d3
If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents:
702
diff
changeset
|
102 <note> |
9fce700e56d3
If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents:
702
diff
changeset
|
103 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
|
104 was considered a false value. |
9fce700e56d3
If: only empty strings and "0" evaluate to false.
Ruslan Ermilov <ru@nginx.com>
parents:
702
diff
changeset
|
105 </note> |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
106 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
107 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
108 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
109 comparing a variable with a string using the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
110 “<literal>=</literal>” and “<literal>!=</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
111 </listitem> |
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 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
114 matching a variable against a regular expression using the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
115 “<literal>~</literal>” (for case-sensitive matching) and |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
116 “<literal>~*</literal>” (for case-insensitive matching) operators. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
117 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
|
118 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
|
119 Negative operators “<literal>!~</literal>” and “<literal>!~*</literal>” |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
120 are also available. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
121 If a regular expression includes the characters “<literal>}</literal>” |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
122 or “<literal>;</literal>”, the whole expressions should be enclosed |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
123 in single or double quotes. |
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> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
127 checking a file existence with the “<literal>-f</literal>” and |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
128 “<literal>!-f</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> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
132 checking a directory existence with the “<literal>-d</literal>” and |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
133 “<literal>!-d</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
134 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
135 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
136 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
137 checking a file, directory, or symbolic link existence with the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
138 “<literal>-e</literal>” and “<literal>!-e</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
139 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
140 |
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 checking for an executable file with operators “<literal>-x</literal>” |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
143 and “<literal>!-x</literal>” operators. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
144 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
145 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
146 </list> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
147 </para> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
150 Examples: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
151 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
152 if ($http_user_agent ~ MSIE) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
153 rewrite ^(.*)$ /msie/$1 break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
154 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
155 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
156 if ($http_cookie ~* "id=([^;]+)(?:;|$)") { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
157 set $id $1; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
160 if ($request_method = POST) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
161 return 405; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
164 if ($slow) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
165 limit_rate 10k; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
168 if ($invalid_referer) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
169 return 403; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
170 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
171 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
172 <note> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
173 A value of the embedded variable <var>$invalid_referer</var> is set by the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
174 <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
|
175 </note> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
176 </para> |
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 </directive> |
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 <directive name="return"> |
548
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
182 <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
|
183 <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
|
184 <syntax><value>URL</value></syntax> |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
185 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
186 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
187 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
188 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
189 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
190 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
191 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
|
192 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
|
193 a response header. |
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 |
548
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
196 <para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
197 Starting from version 0.8.42, it is possible to specify |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
198 either the URL of redirect (for codes 301, 302, 303, and 307), |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
199 or the <value>text</value> of a response body (for other codes). |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
200 A response body text or URL of redirect can contain variables. |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
201 As a special case, a URL of redirect can be specified as a URI |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
202 local to this server, in which case the full URL of redirect |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
203 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
|
204 <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
|
205 <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
|
206 </para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
207 |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
208 <para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
209 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
|
210 can be specified as the sole parameter. |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
211 Such a parameter should start with the string “<literal>http://</literal>”, |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
212 “<literal>https://</literal>”, or “<literal>$scheme</literal>”. |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
213 A <value>URL</value> can contain variables. |
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 |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
216 <para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
217 <note> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
218 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
|
219 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
|
220 </note> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
221 |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
222 <note> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
223 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
|
224 </note> |
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 |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
227 </directive> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
228 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
229 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
230 <directive name="rewrite"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
231 <syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
232 <value>regex</value> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
233 <value>replacement</value> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
234 [<value>flag</value>]</syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
235 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
236 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
237 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
238 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
239 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
240 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
241 If the specified regular expression matches a URI, the URI is changed |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
242 as specified in the <value>replacement</value> string. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
243 The <literal>rewrite</literal> directives are executed sequentially |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
244 in order of their appearance in the configuration file. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
245 Flags make it possible to terminate further processing of directives. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
246 If a replacement string starts with “<literal>http://</literal>” |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
247 or “<literal>https://</literal>”, the processing stops and a |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
248 redirect is returned to a client. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
249 </para> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
252 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
|
253 <list type="tag"> |
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 <tag-name><literal>last</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
256 <tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
257 stops processing the current set of |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
258 <literal>ngx_http_rewrite_module</literal> directives |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
259 followed by a search for a new location matching the changed URI; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
260 </tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
261 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
262 <tag-name><literal>break</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
263 <tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
264 stops processing the current set of |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
265 <literal>ngx_http_rewrite_module</literal> directives; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
266 </tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
267 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
268 <tag-name><literal>redirect</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
269 <tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
270 returns a temporary redirect with the code 302; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
271 used if a replacement string does not start with |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
272 “<literal>http://</literal>” or “<literal>https://</literal>”; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
273 </tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
274 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
275 <tag-name><literal>permanent</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
276 <tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
277 returns a permanent redirect with the code 301. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
278 </tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
279 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
280 </list> |
548
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
281 The full URL of redirects is formed according to the |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
282 request scheme (<var>$scheme</var>) and the |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
283 <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
|
284 <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
|
285 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
286 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
287 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
288 Example: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
289 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
290 server { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
291 ... |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
292 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
293 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
294 return 403; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
295 ... |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
296 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
297 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
298 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
299 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
300 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
301 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
|
302 location, the <literal>last</literal> flag should be replaced by |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
303 <literal>break</literal>, otherwise nginx will make 10 cycles and |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
304 return the error 500: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
305 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
306 location /download/ { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
307 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
308 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
309 return 403; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
310 } |
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 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
313 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
314 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
315 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
|
316 the previous request arguments are appended after them. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
317 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
|
318 string avoids having them appended, for example: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
319 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
320 rewrite ^/users/(.*)$ /show?user=$1? last; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
321 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
322 </para> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
325 If a regular expression includes the characters “<literal>}</literal>” |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
326 or “<literal>;</literal>”, the whole expressions should be enclosed |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
327 in single or double quotes. |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
330 </directive> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
331 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
332 |
673
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
333 <directive name="rewrite_log"> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
334 <syntax><literal>on</literal> | <literal>off</literal></syntax> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
335 <default>off</default> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
336 <context>http</context> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
337 <context>server</context> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
338 <context>location</context> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
339 <context>if</context> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
340 |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
341 <para> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 the <literal>notice</literal> level. |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
346 </para> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
347 |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
348 </directive> |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
349 |
f2d8603813b0
Documented the "rewrite_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
589
diff
changeset
|
350 |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
351 <directive name="set"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
352 <syntax><value>variable</value> <value>value</value></syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
353 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
354 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
355 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
356 <context>if</context> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
359 Sets a <value>value</value> for the specified <value>variable</value>. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
360 A <value>value</value> can contain text, variables, and their combination. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
361 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
362 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
363 </directive> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
364 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
365 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
366 <directive name="uninitialized_variable_warn"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
367 <syntax><literal>on</literal> | <literal>off</literal></syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
368 <default>on</default> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
369 <context>http</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
370 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
371 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
372 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
373 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
374 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
375 Controls whether warnings about uninitialized variables are logged. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
376 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
377 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
378 </directive> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
379 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
380 </section> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
381 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
382 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
383 <section id="internals" name="Internal Implementation"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
384 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
385 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
386 The <literal>ngx_http_rewrite_module</literal> module directives |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
387 are compiled during the configuration stage into internal instructions |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
388 that are interpreted during request processing. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
389 An interpreter is a simple virtual stack machine. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
390 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
391 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
392 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
393 For example, the directives |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
394 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
395 location /download/ { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
396 if ($forbidden) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
397 return 403; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
398 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
399 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
400 if ($slow) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
401 limit_rate 10k; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
404 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break; |
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 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
407 will be translated into these instructions: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
408 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
409 variable $forbidden |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
410 check against zero |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
411 return 403 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
412 end of code |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
413 variable $slow |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
414 check against zero |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
415 match of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
416 copy "/" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
417 copy $1 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
418 copy "/mp3/" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
419 copy $2 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
420 copy ".mp3" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
421 end of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
422 end of code |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
423 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
424 </para> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
427 Note that there are no instructions for the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
428 <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
|
429 directive above as it is unrelated to the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
430 <literal>ngx_http_rewrite_module</literal> module. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
431 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
|
432 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
|
433 where <literal>limit_rate</literal> equals to 10k. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
434 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
435 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
436 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
437 The directive |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
438 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
439 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
440 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
441 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
|
442 is put inside the parentheses: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
443 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
444 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
|
445 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
446 The corresponding instructions will then look like this: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
447 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
448 match of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
449 copy $1 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
450 copy "/mp3/" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
451 copy $2 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
452 copy ".mp3" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
453 end of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
454 end of code |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
455 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
456 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
457 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
458 </section> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
459 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
460 </module> |