comparison xml/it/docs/http/converting_rewrite_rules.xml @ 1053:6303d4e343a8

Updated the Italian translation.
author Vladimir Homutov <vl@nginx.com>
date Mon, 27 Jan 2014 19:25:54 +0400
parents
children
comparison
equal deleted inserted replaced
1052:f5b15dfb72a1 1053:6303d4e343a8
1 <!--
2 Copyright (C) Igor Sysoev
3 Copyright (C) Nginx, Inc.
4 -->
5
6 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
7
8 <article name="Convertire rewrite rule"
9 link="/it/docs/http/converting_rewrite_rules.html"
10 lang="it"
11 translator="Angelo Papadia"
12 rev="1">
13
14
15 <section name="Redirect ad un sito principale">
16
17 <para>
18 Chi, nel corso della propria esperienza con host condivisi, e' sempre
19 stato abituato a configurare <i>tutto</i> usando <i>solo</i> i file
20 .htaccess di Apache, in genere converte le seguenti regole:
21
22 <programlisting>
23 RewriteCond %{HTTP_HOST} example.org
24 RewriteRule (.*) http://www.example.org$1
25 </programlisting>
26
27 in qualcosa tipo:
28
29 <programlisting>
30 server {
31 listen 80;
32 server_name www.example.org example.org;
33 if ($http_host = example.org) {
34 rewrite (.*) http://www.example.org$1;
35 }
36 ...
37 }
38 </programlisting>
39 </para>
40
41 <para>
42 Si tratta di una soluzione errata, poco elegante e inefficiente.
43 La soluzione corretta prevede la definizione di un server distinto per
44 <literal>example.org</literal>:
45
46 <programlisting>
47 server {
48 listen 80;
49 server_name example.org;
50 return 301 http://www.example.org$request_uri;
51 }
52
53 server {
54 listen 80;
55 server_name www.example.org;
56 ...
57 }
58 </programlisting>
59
60 <note>
61 Nelle versioni antecedenti la 0.9.1, i redirect possono essere definiti con:
62 <programlisting>
63 rewrite ^ http://www.example.org$request_uri?;
64 </programlisting>
65 </note>
66
67 </para>
68
69 </section>
70
71
72 <section>
73
74 <para>
75 Un altro esempio:
76 invece della logica &ldquo;upside-down&rdquo;, vale a dire &ldquo;tutto quello
77 che non e' <literal>example.com</literal> ne' <literal>www.example.com</literal>&rdquo;:
78
79 <programlisting>
80 RewriteCond %{HTTP_HOST} !example.com
81 RewriteCond %{HTTP_HOST} !www.example.com
82 RewriteRule (.*) http://www.example.com$1
83 </programlisting>
84
85 e' meglio semplicemente definire
86 <literal>example.com</literal>, <literal>www.example.com</literal>,
87 e &ldquo;tutto il resto&rdquo;:
88
89 <programlisting>
90 server {
91 listen 80;
92 server_name example.com www.example.com;
93 ...
94 }
95
96 server {
97 listen 80 default_server;
98 server_name _;
99 return 301 http://example.com$request_uri;
100 }
101 </programlisting>
102
103 <note>
104 Nelle versioni antecedenti la 0.9.1, i redirect possono essere definiti con:
105 <programlisting>
106 rewrite ^ http://example.com$request_uri?;
107 </programlisting>
108 </note>
109
110 </para>
111
112 </section>
113
114
115 <section id="converting_mongrel_rules"
116 name="Conversione delle regole di Mongrel">
117
118 <para>
119 Regole di Mongrel tipiche, quali:
120
121 <programlisting>
122 DocumentRoot /var/www/myapp.com/current/public
123
124 RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
125 RewriteCond %{SCRIPT_FILENAME} !maintenance.html
126 RewriteRule ^.*$ %{DOCUMENT_ROOT}/system/maintenance.html [L]
127
128 RewriteCond %{REQUEST_FILENAME} -f
129 RewriteRule ^(.*)$ $1 [QSA,L]
130
131 RewriteCond %{REQUEST_FILENAME}/index.html -f
132 RewriteRule ^(.*)$ $1/index.html [QSA,L]
133
134 RewriteCond %{REQUEST_FILENAME}.html -f
135 RewriteRule ^(.*)$ $1/index.html [QSA,L]
136
137 RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
138 </programlisting>
139
140 andrebbero convertite in:
141
142 <programlisting>
143 location / {
144 root /var/www/myapp.com/current/public;
145
146 try_files /system/maintenance.html
147 $uri $uri/index.html $uri.html
148 @mongrel;
149 }
150
151 location @mongrel {
152 proxy_pass http://mongrel;
153 }
154 </programlisting>
155 </para>
156
157 </section>
158
159 </article>