Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/he/docs/http/converting_rewrite_rules.xml
1 views
1
<!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
2
3
<article name="המרת כללי rewrite"
4
link="/he/docs/http/converting_rewrite_rules.html"
5
lang="he"
6
author="Igor Sysoev"
7
translator="מבזקים.נט">
8
9
<section name="הפנייה לאתר ראשי">
10
11
<para>
12
משתמשים שבמהלך חיי האירוח המשותף נהגו להגדיר <i>הכל</i> באמצעות
13
שימוש <i>רק</i> בקובצי htaccess. של Apache, יתרגמו בדרך כלל את
14
הכללים הבאים:
15
16
<programlisting>
17
RewriteCond %{HTTP_HOST} example.org
18
RewriteRule (.*) http://www.example.org$1
19
</programlisting>
20
21
למשהו כזה:
22
23
<programlisting>
24
server {
25
listen 80;
26
server_name www.example.org example.org;
27
if ($http_host = example.org) {
28
rewrite (.*) http://www.example.org$1;
29
}
30
...
31
}
32
</programlisting>
33
</para>
34
35
<para>
36
צורה זו היא שגוייה, מסובכת, ולא יעילה.
37
הדרך הנכונה היא להגדיר שרת נפרד עבור <literal>example.org</literal>:
38
39
<programlisting>
40
server {
41
listen 80;
42
server_name example.org;
43
rewrite ^ http://www.example.org$request_uri?;
44
}
45
46
server {
47
listen 80;
48
server_name www.example.org;
49
...
50
}
51
</programlisting>
52
</para>
53
54
</section>
55
56
57
<section>
58
59
<para>
60
דוגמה נוספת, במקום הגיון הפוך: כל מה שהוא לא
61
<literal>example.com</literal> וגם לא <literal>www.example.com</literal>:
62
63
<programlisting>
64
RewriteCond %{HTTP_HOST} !example.com
65
RewriteCond %{HTTP_HOST} !www.example.com
66
RewriteRule (.*) http://www.example.com$1
67
</programlisting>
68
69
עלייך רק להגדיר את <literal>example.com</literal>, <literal>www.example.com</literal>,
70
וכל דבר אחר:
71
72
<programlisting>
73
server {
74
listen 80;
75
server_name example.org www.example.org;
76
...
77
}
78
79
server {
80
listen 80 default_server;
81
server_name _;
82
rewrite ^ http://example.org$request_uri?;
83
}
84
</programlisting>
85
</para>
86
87
</section>
88
89
90
<section id="converting_mongrel_rules"
91
name="המרת כללי Mongrel">
92
93
<para>
94
כללי Mongrel טיפוסיים:
95
96
<programlisting>
97
DocumentRoot /var/www/myapp.com/current/public
98
99
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
100
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
101
RewriteRule ^.*$ %{DOCUMENT_ROOT}/system/maintenance.html [L]
102
103
RewriteCond %{REQUEST_FILENAME} -f
104
RewriteRule ^(.*)$ $1 [QSA,L]
105
106
RewriteCond %{REQUEST_FILENAME}/index.html -f
107
RewriteRule ^(.*)$ $1/index.html [QSA,L]
108
109
RewriteCond %{REQUEST_FILENAME}.html -f
110
RewriteRule ^(.*)$ $1/index.html [QSA,L]
111
112
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
113
</programlisting>
114
115
יש להמיר כך
116
117
<programlisting>
118
location / {
119
root /var/www/myapp.com/current/public;
120
121
try_files /system/maintenance.html
122
$uri $uri/index.html $uri.html
123
@mongrel;
124
}
125
126
location @mongrel {
127
proxy_pass http://mongrel;
128
}
129
</programlisting>
130
</para>
131
132
</section>
133
134
</article>
135
136