1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Rewrite Configuration Guide - Zend Framework Manual</title>
</head>
<body>
<table width="100%">
<tr valign="top">
<td width="85%">
<table width="100%">
<tr>
<td width="25%" style="text-align: left;">
<a href="project-structure.filesystem.html">Module Structure</a>
</td>
<td width="50%" style="text-align: center;">
<div class="up"><span class="up"><a href="project-structure.html">Recommended Project Structure for Zend Framework MVC Applications</a></span><br />
<span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
</td>
<td width="25%" style="text-align: right;">
<div class="next" style="text-align: right; float: right;"><a href="performance.html">Zend Gdata Performance Guide</a></div>
</td>
</tr>
</table>
<hr />
<div id="project-structure.rewrite" class="section"><div class="info"><h1 class="title">Rewrite Configuration Guide</h1></div>
<p class="para">
<acronym class="acronym">URL</acronym> rewriting is a common function of <acronym class="acronym">HTTP</acronym>
servers. However, the rules and configuration differ widely between them. Below are
some common approaches across a variety of popular web servers available at the time of
writing.
</p>
<div class="section" id="project-structure.rewrite.apache" name="project-structure.rewrite.apache"><div class="info"><h1 class="title">Apache HTTP Server</h1></div>
<p class="para">
All examples that follow use <span class="property">mod_rewrite</span>, an official
module that comes bundled with Apache. To use it,
<span class="property">mod_rewrite</span> must either be included at compile time or
enabled as a Dynamic Shared Object (<acronym class="acronym">DSO</acronym>). Please consult the
<a href="http://httpd.apache.org/docs/" class="link external">» Apache documentation</a> for your
version for more information.
</p>
<div class="section" id="project-structure.rewrite.apache.vhost" name="project-structure.rewrite.apache.vhost"><div class="info"><h1 class="title">Rewriting inside a VirtualHost</h1></div>
<p class="para">
Here is a very basic virtual host definition. These rules direct all requests
to <var class="filename">index.php</var>, except when a matching file is found under
the <span class="property">document_root</span>.
</p>
<div class="programlisting text"><div class="textcode"><div class="text" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><VirtualHost my.domain.com:80></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> ServerName my.domain.com</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> DocumentRoot /path/to/server/root/my.domain.com/public</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> RewriteEngine off</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <Location /></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> RewriteEngine On</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> RewriteCond %{REQUEST_FILENAME} -s [OR]</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> RewriteCond %{REQUEST_FILENAME} -l [OR]</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> RewriteCond %{REQUEST_FILENAME} -d</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> RewriteRule ^.*$ - [NC,L]</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> RewriteRule ^.*$ /index.php [NC,L]</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </Location></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"></VirtualHost></div></li></ol></div></div></div>
<p class="para">
Note the slash ("/") prefixing <var class="filename">index.php</var>; the rules for
<var class="filename">.htaccess</var> differ in this regard.
</p>
</div>
<div class="section" id="project-structure.rewrite.apache.htaccess" name="project-structure.rewrite.apache.htaccess"><div class="info"><h1 class="title">Rewriting within a .htaccess file</h1></div>
<p class="para">
Below is a sample <var class="filename">.htaccess</var> file that utilizes
<span class="property">mod_rewrite</span>. It is similar to the virtual host
configuration, except that it specifies only the rewrite rules, and the leading
slash is omitted from <var class="filename">index.php</var>.
</p>
<div class="programlisting text"><div class="textcode"><div class="text" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteEngine On</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteCond %{REQUEST_FILENAME} -s [OR]</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteCond %{REQUEST_FILENAME} -l [OR]</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteCond %{REQUEST_FILENAME} -d</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteRule ^.*$ - [NC,L]</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">RewriteRule ^.*$ index.php [NC,L]</div></li></ol></div></div></div>
<p class="para">
There are many ways to configure <span class="property">mod_rewrite</span>; if you
would like more information, see Jayson Minard's <a href="http://devzone.zend.com/a/70" class="link external">» Blueprint for PHP Applications:
Bootstrapping</a>.
</p>
</div>
</div>
<div class="section" id="project-structure.rewrite.iis" name="project-structure.rewrite.iis"><div class="info"><h1 class="title">Microsoft Internet Information Server</h1></div>
<p class="para">
As of version 7.0, <acronym class="acronym">IIS</acronym> now ships with a standard rewrite engine.
You may use the following configuration to create the appropriate rewrite rules.
</p>
<div class="programlisting xml"><div class="xmlcode"><div class="xml" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;"><?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">"1.0"</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">"UTF-8"</span><span style="font-weight: bold; color: black;">?></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;"><configuration<span style="font-weight: bold; color: black;">></span></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><system</span>.webServer<span style="font-weight: bold; color: black;">></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rewrite<span style="font-weight: bold; color: black;">></span></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rules<span style="font-weight: bold; color: black;">></span></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Imported Rule 1"</span> <span style="color: #000066;">stopProcessing</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">"^.*$"</span> <span style="font-weight: bold; color: black;">/></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><conditions</span> <span style="color: #000066;">logicalGrouping</span>=<span style="color: #ff0000;">"MatchAny"</span><span style="font-weight: bold; color: black;">></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">"{REQUEST_FILENAME}"</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #000066;">matchType</span>=<span style="color: #ff0000;">"IsFile"</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">""</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #000066;">ignoreCase</span>=<span style="color: #ff0000;">"false"</span> <span style="font-weight: bold; color: black;">/></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><add</span> <span style="color: #000066;">input</span>=<span style="color: #ff0000;">"{REQUEST_FILENAME}"</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #000066;">matchType</span>=<span style="color: #ff0000;">"IsDirectory"</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">""</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #000066;">ignoreCase</span>=<span style="color: #ff0000;">"false"</span> <span style="font-weight: bold; color: black;">/></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"></conditions<span style="font-weight: bold; color: black;">></span></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"None"</span> <span style="font-weight: bold; color: black;">/></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"></rule<span style="font-weight: bold; color: black;">></span></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><rule</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"Imported Rule 2"</span> <span style="color: #000066;">stopProcessing</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><match</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">"^.*$"</span> <span style="font-weight: bold; color: black;">/></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"><action</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"Rewrite"</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">"index.php"</span> <span style="font-weight: bold; color: black;">/></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"></rule<span style="font-weight: bold; color: black;">></span></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"></rules<span style="font-weight: bold; color: black;">></span></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"></rewrite<span style="font-weight: bold; color: black;">></span></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #009900;"><span style="font-weight: bold; color: black;"></system</span>.webServer<span style="font-weight: bold; color: black;">></span></span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;"></configuration<span style="font-weight: bold; color: black;">></span></span></span></div></li></ol></div></div></div>
</div>
</div>
<hr />
<table width="100%">
<tr>
<td width="25%" style="text-align: left;">
<a href="project-structure.filesystem.html">Module Structure</a>
</td>
<td width="50%" style="text-align: center;">
<div class="up"><span class="up"><a href="project-structure.html">Recommended Project Structure for Zend Framework MVC Applications</a></span><br />
<span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
</td>
<td width="25%" style="text-align: right;">
<div class="next" style="text-align: right; float: right;"><a href="performance.html">Zend Gdata Performance Guide</a></div>
</td>
</tr>
</table>
</td>
<td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
float: left;
width: 186px;
padding: 5px;
font-size: smaller;
}
ul.toc {
margin: 0px 5px 5px 5px;
padding: 0px;
}
ul.toc li {
font-size: 85%;
margin: 1px 0 1px 1px;
padding: 1px 0 1px 11px;
list-style-type: none;
background-repeat: no-repeat;
background-position: center left;
}
ul.toc li.header {
font-size: 115%;
padding: 5px 0px 5px 11px;
border-bottom: 1px solid #cccccc;
margin-bottom: 5px;
}
ul.toc li.active {
font-weight: bold;
}
ul.toc li a {
text-decoration: none;
}
ul.toc li a:hover {
text-decoration: underline;
}
</style>
<ul class="toc">
<li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
<li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
<li class="header up"><a href="project-structure.html">Recommended Project Structure for Zend Framework MVC Applications</a></li>
<li><a href="project-structure.overview.html">Overview</a></li>
<li><a href="project-structure.project.html">Recommended Project Directory Structure</a></li>
<li><a href="project-structure.filesystem.html">Module Structure</a></li>
<li class="active"><a href="project-structure.rewrite.html">Rewrite Configuration Guide</a></li>
</ul>
</td>
</tr>
</table>
</body>
</html>
|