-
Where can I find
mod_rewrite rulesets which already solve particular URL-related problems?
There is a collection of Practical
Solutions for URL-Manipulation where you can find all typical solutions the author of
mod_rewrite
currently knows of. If you have more interesting rulesets which solve particular problems
not currently covered in this document, send it to Ralf S.
Engelschall for inclusion. The other webmasters will thank you for avoiding the
reinvention of the wheel.
-
Where can I find any published
information about URL-manipulations and mod_rewrite?
There is an article from Ralf S. Engelschall about
URL-manipulations based on
mod_rewrite
in the "iX Multiuser Multitasking Magazin" issue #12/96. The german (original)
version can be read online at <http://www.heise.de/ix/artikel/9612149/>,
the English (translated) version can be found at <http://www.heise.de/ix/artikel/E/9612149/>.
-
Why is mod_rewrite so
difficult to learn and seems so complicated?
Hmmm... there are a lot of reasons. First, mod_rewrite itself is a powerful module
which can help you in really all 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.
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 .htaccess 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.
-
What can I do if my
RewriteRules don't work as expected?
Use "RewriteLog somefile" and "RewriteLogLevel 9"
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.
-
Why don't some of my
URLs get prefixed with DocumentRoot when using mod_rewrite?
If the rule starts with /somedir/... make sure that really no /somedir
exists on the filesystem if you don't want to lead the URL to match this directory, i.e.,
there must be no root directory named somedir 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.
-
How can I make all my URLs
case-insensitive with mod_rewrite?
You can't! The reasons are: first, that, case translations for arbitrary length URLs
cannot be done via regex patterns and corresponding substitutions. One needs a
per-character pattern like the sed/Perl tr|..|..| 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.
But there is a module named
mod_speling.c in the
Apache distribution. Try this module to help correct people who use mis-cased URLs.
-
Why are RewriteRules in my
VirtualHost parts ignored?
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.
-
How can I use strings
with whitespaces in RewriteRule's ENV flag?
There is only one ugly solution: You have to surround the complete flag argument by
quotation marks ("[E=...]"). Notice: The argument to quote here is
not the argument to the E-flag, it is the argument of the Apache config file parser, i.e.,
the third argument of the RewriteRule here. So you have to write "[E=any text
with whitespaces]".