Apache Server Frequently Asked Questions

$Revision: 1.99 $ ($Date: 2010/12/10 10:13:45 $)

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 more recent version of the server. Information obtained here is likely to be outdated and inaccurate.

The latest version of this FAQ is available on the HTTP Server Wiki, at <http://httpd.apache.org/docs/1.3/misc/FAQ.html>. This version is no longer maintained, and contains inaccurate and grossly outdated information.

The Questions

  1. URL Rewriting
    1. Where can I find mod_rewrite rulesets which already solve particular URL-related problems?
    2. Where can I find any published information about URL-manipulations and mod_rewrite?
    3. Why is mod_rewrite so difficult to learn and seems so complicated?
    4. What can I do if my RewriteRules don't work as expected?
    5. Why don't some of my URLs get prefixed with DocumentRoot when using mod_rewrite?
    6. How can I make all my URLs case-insensitive with mod_rewrite?
    7. Why are RewriteRules in my VirtualHost parts ignored?
    8. How can I use strings with whitespaces in RewriteRule's ENV flag?

The Answers

H. URL Rewriting

  1. Where can I find mod_rewrite rulesets which already solve particular URL-related problems?

    There is a collection of practical solutions that can be found in the Apache 1.3 URL Rewriting Guide. 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.


  2. 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/1996/12/149/>, the English (translated) version can be found at <http://www.heise.de/ix/artikel/E/1996/12/149/>.


  3. 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.


  4. 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.


  5. 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.


  6. 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.


  7. 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.


  8. 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]".