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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
<!--#if expr="$FAQMASTER" -->
<!--#set var="STANDALONE" value="" -->
<!--#set var="INCLUDED" value="YES" -->
<!--#if expr="$QUERY_STRING = TOC" -->
<!--#set var="TOC" value="YES" -->
<!--#set var="CONTENT" value="" -->
<!--#else -->
<!--#set var="TOC" value="" -->
<!--#set var="CONTENT" value="YES" -->
<!--#endif -->
<!--#else -->
<!--#set var="STANDALONE" value="YES" -->
<!--#set var="INCLUDED" value="" -->
<!--#set var="TOC" value="" -->
<!--#set var="CONTENT" value="" -->
<!--#endif -->
<!--#if expr="$STANDALONE" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<meta name="generator" content="HTML Tidy, see www.w3.org" />
<title>Apache Server Frequently Asked Questions</title>
</head>
<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
vlink="#000080" alink="#FF0000">
<!--#include virtual="../header_l2.html" -->
<h1 align="CENTER">Apache Server Frequently Asked
Questions</h1>
<p>$Revision: 1.99 $ ($Date: 2010/12/10 10:13:45 $)</p>
<p><b>Please note that this document refers to a version of the
product which has been deprecated, and declared "end of life", in
favor of the <a href="http://httpd.apache.org/docs/current">more recent
version of the server</a>. Information obtained here is likely to be
outdated and inaccurate.</b></p>
<p>The latest version of this FAQ is available on the HTTP Server
Wiki, at <<a href="http://wiki.apache.org/httpd/FAQ" rel="Help"
><samp>http://httpd.apache.org/docs/1.3/misc/FAQ.html</samp></a>>.
This version is no longer maintained, and contains inaccurate
and grossly outdated information.</p>
<!-- Notes about changes: Don't make any. Make them in the wiki. -->
<h2>The Questions</h2>
<ol type="A">
<!--#endif -->
<!--#if expr="$TOC || $STANDALONE" -->
<li value="8">
<strong>URL Rewriting</strong>
<ol>
<li><a href="#rewrite-more-config">Where can I find
mod_rewrite rulesets which already solve particular
URL-related problems?</a></li>
<li><a href="#rewrite-article">Where can I find any
published information about URL-manipulations and
mod_rewrite?</a></li>
<li><a href="#rewrite-complexity">Why is mod_rewrite so
difficult to learn and seems so complicated?</a></li>
<li><a href="#rewrite-dontwork">What can I do if my
RewriteRules don't work as expected?</a></li>
<li><a href="#rewrite-prefixdocroot">Why don't some of my
URLs get prefixed with DocumentRoot when using
mod_rewrite?</a></li>
<li><a href="#rewrite-nocase">How can I make all my URLs
case-insensitive with mod_rewrite?</a></li>
<li><a href="#rewrite-virthost">Why are RewriteRules in
my VirtualHost parts ignored?</a></li>
<li><a href="#rewrite-envwhitespace">How can I use
strings with whitespaces in RewriteRule's ENV
flag?</a></li>
</ol>
</li>
<!--#endif -->
<!--#if expr="$STANDALONE" -->
</ol>
<hr />
<h2>The Answers</h2>
<!--#endif -->
<!--#if expr="! $TOC" -->
<h3>H. URL Rewriting</h3>
<ol>
<li>
<a id="rewrite-more-config"
name="rewrite-more-config"><strong>Where can I find
mod_rewrite rulesets which already solve particular
URL-related problems?</strong></a>
<p>There is a collection of practical solutions that can be
found in the
<a href="rewriteguide.html">Apache 1.3 URL Rewriting Guide</a>.
If you have more interesting rulesets
which solve particular problems not currently covered in
this document, send it to <a
href="mailto:rse@apache.org">Ralf S. Engelschall</a> for
inclusion. The other webmasters will thank you for avoiding
the reinvention of the wheel.</p>
<hr />
</li>
<li>
<a id="rewrite-article"
name="rewrite-article"><strong>Where can I find any
published information about URL-manipulations and
mod_rewrite?</strong></a>
<p>There is an article from <a
href="mailto:rse@apache.org">Ralf S. Engelschall</a> about
URL-manipulations based on <a
href="../mod/mod_rewrite.html"><samp>mod_rewrite</samp></a>
in the "iX Multiuser Multitasking Magazin" issue #12/96.
The German (original) version can be read online at <<a
href="http://www.heise.de/ix/artikel/1996/12/149/">http://www.heise.de/ix/artikel/1996/12/149/</a>>,
the English (translated) version can be found at <<a
href="http://www.heise.de/ix/artikel/E/1996/12/149/">http://www.heise.de/ix/artikel/E/1996/12/149/</a>>.</p>
<hr />
</li>
<li>
<a id="rewrite-complexity"
name="rewrite-complexity"><strong>Why is mod_rewrite so
difficult to learn and seems so complicated?</strong></a>
<p>Hmmm... there are a lot of reasons. First, mod_rewrite
itself is a powerful module which can help you in really
<strong>all</strong> aspects of URL rewriting, so it can be
no trivial module per definition. To accomplish its hard
job it uses software leverage and makes use of a powerful
regular expression library by Henry Spencer which is an
integral part of Apache since its version 1.2. And regular
expressions itself can be difficult to newbies, while
providing the most flexible power to the advanced
hacker.</p>
<p>On the other hand mod_rewrite has to work inside the
Apache API environment and needs to do some tricks to fit
there. For instance the Apache API as of 1.x really was not
designed for URL rewriting at the <tt>.htaccess</tt> level
of processing. Or the problem of multiple rewrites in
sequence, which is also not handled by the API per design.
To provide this features mod_rewrite has to do some special
(but API compliant!) handling which leads to difficult
processing inside the Apache kernel. While the user usually
doesn't see anything of this processing, it can be
difficult to find problems when some of your RewriteRules
seem not to work.</p>
<hr />
</li>
<li>
<a id="rewrite-dontwork"
name="rewrite-dontwork"><strong>What can I do if my
RewriteRules don't work as expected?</strong></a>
<p>Use "<samp>RewriteLog somefile</samp>" and
"<samp>RewriteLogLevel 9</samp>" and have a precise look at
the steps the rewriting engine performs. This is really the
only one and best way to debug your rewriting
configuration.</p>
<hr />
</li>
<li>
<a id="rewrite-prefixdocroot"
name="rewrite-prefixdocroot"><strong>Why don't some of my
URLs get prefixed with DocumentRoot when using
mod_rewrite?</strong></a>
<p>If the rule starts with <samp>/somedir/...</samp> make
sure that really no <samp>/somedir</samp> exists on the
filesystem if you don't want to lead the URL to match this
directory, <em>i.e.</em>, there must be no root directory
named <samp>somedir</samp> on the filesystem. Because if
there is such a directory, the URL will not get prefixed
with DocumentRoot. This behavior looks ugly, but is really
important for some other aspects of URL rewriting.</p>
<hr />
</li>
<li>
<a id="rewrite-nocase" name="rewrite-nocase"><strong>How
can I make all my URLs case-insensitive with
mod_rewrite?</strong></a>
<p>You can't! The reasons are: first, that, case
translations for arbitrary length URLs cannot be done
<em>via</em> regex patterns and corresponding
substitutions. One needs a per-character pattern like the
sed/Perl <samp>tr|..|..|</samp> feature. Second, just
making URLs always upper or lower case does not solve the
whole problem of case-INSENSITIVE URLs, because URLs
actually have to be rewritten to the correct case-variant
for the file residing on the filesystem in order to allow
Apache to access the file. And the Unix filesystem is
always case-SENSITIVE.</p>
<p>But there is a module named <code><a
href="../mod/mod_speling.html">mod_speling.c</a></code> in
the Apache distribution. Try this module to help correct
people who use mis-cased URLs.</p>
<hr />
</li>
<li>
<a id="rewrite-virthost"
name="rewrite-virthost"><strong>Why are RewriteRules in my
VirtualHost parts ignored?</strong></a>
<p>Because you have to enable the engine for every virtual
host explicitly due to security concerns. Just add a
"RewriteEngine on" to your virtual host configuration
parts.</p>
<hr />
</li>
<li>
<a id="rewrite-envwhitespace"
name="rewrite-envwhitespace"><strong>How can I use strings
with whitespaces in RewriteRule's ENV flag?</strong></a>
<p>There is only one ugly solution: You have to surround
the complete flag argument by quotation marks
(<samp>"[E=...]"</samp>). Notice: The argument to quote
here is not the argument to the E-flag, it is the argument
of the Apache config file parser, <em>i.e.</em>, the third
argument of the RewriteRule here. So you have to write
<samp>"[E=any text with whitespaces]"</samp>.</p>
<hr />
</li>
</ol>
<!--#endif -->
<!--#if expr="$STANDALONE" -->
<!-- Don't forget to add HR tags at the end of each list item.. -->
<!--#include virtual="footer.html" -->
<!--#endif -->
</body>
</html>
|