Mercurial > hg > nginx-site
comparison xml/en/docs/http/converting_rewrite_rules.xml @ 490:9913f1d51c07
Replaced "nginx" domain names with example domains.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Thu, 19 Apr 2012 12:30:24 +0000 |
parents | 7db449e89e92 |
children | be54c443235a |
comparison
equal
deleted
inserted
replaced
489:2abd1998a0cc | 490:9913f1d51c07 |
---|---|
11 People who during their shared hosting life used to configure | 11 People who during their shared hosting life used to configure |
12 <i>everything</i> using <i>only</i> Apache’s .htaccess files, | 12 <i>everything</i> using <i>only</i> Apache’s .htaccess files, |
13 usually translate the following rules: | 13 usually translate the following rules: |
14 | 14 |
15 <programlisting> | 15 <programlisting> |
16 RewriteCond %{HTTP_HOST} nginx.org | 16 RewriteCond %{HTTP_HOST} example.org |
17 RewriteRule (.*) http://www.nginx.org$1 | 17 RewriteRule (.*) http://www.example.org$1 |
18 </programlisting> | 18 </programlisting> |
19 | 19 |
20 to something like this: | 20 to something like this: |
21 | 21 |
22 <programlisting> | 22 <programlisting> |
23 server { | 23 server { |
24 listen 80; | 24 listen 80; |
25 server_name www.nginx.org nginx.org; | 25 server_name www.example.org example.org; |
26 if ($http_host = nginx.org) { | 26 if ($http_host = example.org) { |
27 rewrite (.*) http://www.nginx.org$1; | 27 rewrite (.*) http://www.example.org$1; |
28 } | 28 } |
29 ... | 29 ... |
30 } | 30 } |
31 </programlisting> | 31 </programlisting> |
32 </para> | 32 </para> |
33 | 33 |
34 <para> | 34 <para> |
35 This is a wrong, cumbersome, and ineffective way. | 35 This is a wrong, cumbersome, and ineffective way. |
36 The right way is to define a separate server for <url>nginx.org</url>: | 36 The right way is to define a separate server for <url>example.org</url>: |
37 | 37 |
38 <programlisting> | 38 <programlisting> |
39 server { | 39 server { |
40 listen 80; | 40 listen 80; |
41 server_name nginx.org; | 41 server_name example.org; |
42 return 301 http://www.nginx.org$request_uri; | 42 return 301 http://www.example.org$request_uri; |
43 } | 43 } |
44 | 44 |
45 server { | 45 server { |
46 listen 80; | 46 listen 80; |
47 server_name www.nginx.org; | 47 server_name www.example.org; |
48 ... | 48 ... |
49 } | 49 } |
50 </programlisting> | 50 </programlisting> |
51 | 51 |
52 <note> | 52 <note> |
53 On versions prior to 0.9.1, redirects can be made with: | 53 On versions prior to 0.9.1, redirects can be made with: |
54 <programlisting> | 54 <programlisting> |
55 rewrite ^ http://www.nginx.org$request_uri?; | 55 rewrite ^ http://www.example.org$request_uri?; |
56 </programlisting> | 56 </programlisting> |
57 </note> | 57 </note> |
58 | 58 |
59 </para> | 59 </para> |
60 | 60 |
64 <section> | 64 <section> |
65 | 65 |
66 <para> | 66 <para> |
67 Another example. | 67 Another example. |
68 Instead of the “upside-down” logic “all that is not | 68 Instead of the “upside-down” logic “all that is not |
69 <url>nginx.com</url> and is not <url>www.nginx.com</url>”: | 69 <url>example.com</url> and is not <url>www.example.com</url>”: |
70 | 70 |
71 <programlisting> | 71 <programlisting> |
72 RewriteCond %{HTTP_HOST} !nginx.com | 72 RewriteCond %{HTTP_HOST} !example.com |
73 RewriteCond %{HTTP_HOST} !www.nginx.com | 73 RewriteCond %{HTTP_HOST} !www.example.com |
74 RewriteRule (.*) http://www.nginx.com$1 | 74 RewriteRule (.*) http://www.example.com$1 |
75 </programlisting> | 75 </programlisting> |
76 | 76 |
77 one should simply define <url>nginx.com</url>, <url>www.nginx.com</url>, | 77 one should simply define <url>example.com</url>, <url>www.example.com</url>, |
78 and “everything else”: | 78 and “everything else”: |
79 | 79 |
80 <programlisting> | 80 <programlisting> |
81 server { | 81 server { |
82 listen 80; | 82 listen 80; |
83 server_name nginx.com www.nginx.com; | 83 server_name example.com www.example.com; |
84 ... | 84 ... |
85 } | 85 } |
86 | 86 |
87 server { | 87 server { |
88 listen 80 default_server; | 88 listen 80 default_server; |
89 server_name _; | 89 server_name _; |
90 return 301 http://nginx.com$request_uri; | 90 return 301 http://example.com$request_uri; |
91 } | 91 } |
92 </programlisting> | 92 </programlisting> |
93 | 93 |
94 <note> | 94 <note> |
95 On versions prior to 0.9.1, redirects can be made with: | 95 On versions prior to 0.9.1, redirects can be made with: |
96 <programlisting> | 96 <programlisting> |
97 rewrite ^ http://nginx.com$request_uri?; | 97 rewrite ^ http://example.com$request_uri?; |
98 </programlisting> | 98 </programlisting> |
99 </note> | 99 </note> |
100 | 100 |
101 </para> | 101 </para> |
102 | 102 |