Mercurial > hg > nginx-site
annotate xml/en/docs/http/ngx_http_rewrite_module.xml @ 589:764fbac1b8b4
Added document revision.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 17 Jul 2012 05:02:15 +0000 |
parents | be54c443235a |
children | f2d8603813b0 |
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" |
13 rev="1"> | |
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. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
41 This cycle may be repeated up to 10 times after which the error |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
42 <http-status code="500" text="Internal Server Error"/> is returned. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
43 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
44 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
45 </list> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
46 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
47 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
48 </section> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
51 <section id="directives" name="Directives"> |
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 <directive name="break"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
54 <syntax/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
55 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
56 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
57 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
58 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
59 |
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 Stops processing the current set of |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
62 <literal>ngx_http_rewrite_module</literal> directives. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
63 </para> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
66 Example: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
67 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
68 if ($slow) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
69 limit_rate 10k; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
70 break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
71 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
72 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
73 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
74 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
75 </directive> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
78 <directive name="if"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
79 <syntax block="yes">(<value>condition</value>)</syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
80 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
81 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
82 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
83 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
84 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
85 The specified <value>condition</value> is evaluated. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
86 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
|
87 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
|
88 <literal>if</literal> directive. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
89 Configurations inside the <literal>if</literal> directives are |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
90 inherited from the previous configuration level. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
91 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
92 |
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 A condition may be any of the following: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
95 <list type="bullet"> |
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 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
98 a variable name; false if the value of a variable is an empty string |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
99 or any string starting with “<literal>0</literal>”; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
100 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
101 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
102 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
103 comparing a variable with a string using the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
104 “<literal>=</literal>” and “<literal>!=</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
105 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
106 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
107 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
108 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
|
109 “<literal>~</literal>” (for case-sensitive matching) and |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
110 “<literal>~*</literal>” (for case-insensitive matching) operators. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
111 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
|
112 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
|
113 Negative operators “<literal>!~</literal>” and “<literal>!~*</literal>” |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
114 are also available. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
115 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
|
116 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
|
117 in single or double quotes. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
118 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
119 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
120 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
121 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
|
122 “<literal>!-f</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
123 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
124 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
125 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
126 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
|
127 “<literal>!-d</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
128 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
129 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
130 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
131 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
|
132 “<literal>-e</literal>” and “<literal>!-e</literal>” operators; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
133 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
134 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
135 <listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
136 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
|
137 and “<literal>!-x</literal>” operators. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
138 </listitem> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
139 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
140 </list> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
141 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
142 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
143 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
144 Examples: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
145 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
146 if ($http_user_agent ~ MSIE) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
147 rewrite ^(.*)$ /msie/$1 break; |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
150 if ($http_cookie ~* "id=([^;]+)(?:;|$)") { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
151 set $id $1; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
152 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
153 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
154 if ($request_method = POST) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
155 return 405; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
156 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
157 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
158 if ($slow) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
159 limit_rate 10k; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
160 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
161 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
162 if ($invalid_referer) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
163 return 403; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
164 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
165 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
166 <note> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
167 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
|
168 <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
|
169 </note> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
170 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
171 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
172 </directive> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
175 <directive name="return"> |
548
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
176 <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
|
177 <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
|
178 <syntax><value>URL</value></syntax> |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
179 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
180 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
181 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
182 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
183 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
184 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
185 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
|
186 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
|
187 a response header. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
188 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
189 |
548
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
190 <para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 <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
|
199 <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
|
200 </para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
201 |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
202 <para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
203 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
|
204 can be specified as the sole parameter. |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
205 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
|
206 “<literal>https://</literal>”, or “<literal>$scheme</literal>”. |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
207 A <value>URL</value> can contain variables. |
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 |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
210 <para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
211 <note> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
212 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
|
213 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
|
214 </note> |
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 <note> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
217 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
|
218 </note> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
219 </para> |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
220 |
392
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
221 </directive> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
222 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
223 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
224 <directive name="rewrite"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
225 <syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
226 <value>regex</value> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
227 <value>replacement</value> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
228 [<value>flag</value>]</syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
229 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
230 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
231 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
232 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
233 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
234 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
235 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
|
236 as specified in the <value>replacement</value> string. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
237 The <literal>rewrite</literal> directives are executed sequentially |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
238 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
|
239 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
|
240 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
|
241 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
|
242 redirect is returned to a client. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
243 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
244 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
245 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
246 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
|
247 <list type="tag"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
248 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
249 <tag-name><literal>last</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
250 <tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
251 stops processing the current set of |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
252 <literal>ngx_http_rewrite_module</literal> directives |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
253 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
|
254 </tag-desc> |
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 <tag-name><literal>break</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
257 <tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
258 stops processing the current set of |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
259 <literal>ngx_http_rewrite_module</literal> directives; |
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>redirect</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 returns a temporary redirect with the code 302; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
265 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
|
266 “<literal>http://</literal>” or “<literal>https://</literal>”; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
267 </tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
268 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
269 <tag-name><literal>permanent</literal></tag-name> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
270 <tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
271 returns a permanent redirect with the code 301. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
272 </tag-desc> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
273 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
274 </list> |
548
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
275 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
|
276 request scheme (<var>$scheme</var>) and the |
95a970603b0f
Brought the "return" documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
402
diff
changeset
|
277 <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
|
278 <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
|
279 </para> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
282 Example: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
283 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
284 server { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
285 ... |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
286 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
287 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
288 return 403; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
289 ... |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
290 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
291 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
292 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
293 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
294 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
295 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
|
296 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
|
297 <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
|
298 return the error 500: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
299 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
300 location /download/ { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
301 rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
302 rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
303 return 403; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
304 } |
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 </para> |
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 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
309 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
|
310 the previous request arguments are appended after them. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
311 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
|
312 string avoids having them appended, for example: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
313 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
314 rewrite ^/users/(.*)$ /show?user=$1? last; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
315 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
316 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
317 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
318 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
319 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
|
320 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
|
321 in single or double quotes. |
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 </directive> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
325 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
326 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
327 <directive name="set"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
328 <syntax><value>variable</value> <value>value</value></syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
329 <default/> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
330 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
331 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
332 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
333 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
334 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
335 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
|
336 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
|
337 </para> |
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 </directive> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
340 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
341 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
342 <directive name="uninitialized_variable_warn"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
343 <syntax><literal>on</literal> | <literal>off</literal></syntax> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
344 <default>on</default> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
345 <context>http</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
346 <context>server</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
347 <context>location</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
348 <context>if</context> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
349 |
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 Controls whether warnings about uninitialized variables are logged. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
352 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
353 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
354 </directive> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
355 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
356 </section> |
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 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
359 <section id="internals" name="Internal Implementation"> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
360 |
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 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
|
363 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
|
364 that are interpreted during request processing. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
365 An interpreter is a simple virtual stack machine. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
366 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
367 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
368 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
369 For example, the directives |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
370 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
371 location /download/ { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
372 if ($forbidden) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
373 return 403; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
374 } |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
375 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
376 if ($slow) { |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
377 limit_rate 10k; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
378 } |
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 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break; |
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 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
383 will be translated into these instructions: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
384 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
385 variable $forbidden |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
386 check against zero |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
387 return 403 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
388 end of code |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
389 variable $slow |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
390 check against zero |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
391 match of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
392 copy "/" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
393 copy $1 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
394 copy "/mp3/" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
395 copy $2 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
396 copy ".mp3" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
397 end of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
398 end of code |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
399 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
400 </para> |
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 Note that there are no instructions for the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
404 <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
|
405 directive above as it is unrelated to the |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
406 <literal>ngx_http_rewrite_module</literal> module. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
407 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
|
408 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
|
409 where <literal>limit_rate</literal> equals to 10k. |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
410 </para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
411 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
412 <para> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
413 The directive |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
414 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
415 rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break; |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
416 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
417 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
|
418 is put inside the parentheses: |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
419 <example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
420 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
|
421 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
422 The corresponding instructions will then look like this: |
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 match of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
425 copy $1 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
426 copy "/mp3/" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
427 copy $2 |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
428 copy ".mp3" |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
429 end of regular expression |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
430 end of code |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
431 </example> |
5fd99d37a3e6
English translation of ngx_http_rewrite_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
432 </para> |
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 </section> |
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 </module> |