The rewrite rules implement the first step in mapping the "URL space" to the actual content served by Apache. The rules are contained in a file called rewrite.conf, which is included by the httpd.conf. This setup both makes it easier to edit the rules, and to include it in multiple virtual server configurations. In the standard server configuration, both of these files are in the directory /usr/local/apache/conf/.

Most of the entries in rewrite.conf are instances of the RewriteRule directive, which is processed by Apache's mod_rewrite module. (Note: by default, this module is not turned on. It must be turned on with the --enable-module=rewrite argument to Apache's configure script.) Here is an example rule:

  RewriteRule ^/admin$ /admin/ [R,L]
  RewriteRule ^/admin/([^/]*)/?(.*)$ /home/www/php/admin.php3?%{QUERY_STRING} [L]
Ok, so that's two rules :). The first one says that the URL /admin is redirected (that is, the browser is told to redirect) to /admin/. This is the classic trailing-slash redirect. ("R" means redirect, "L" means "last," -- that is, don't process any more rules after this one.)

The second rule says that any URL that starts with /admin/ is rewritten to the PHP script admin.php3 (which is located with the rest of the PHP scripts in the directory /home/www/php). In addition, the query string (arguments following the URL proper, such as ?foo=bar&baz=zaz) is appended to the script name so PHP sees these and turns them into variables.

There is a whole set of such rules, for pages such as the SIGs and GIGs pages, the Admin page, and the Login and Logout pages/scripts. The final rule processes any remaining URLs, which basically means all of the URLs that contain static HTML. This rule looks like this:

  RewriteCond %{REQUEST_FILENAME} !^/php
  RewriteCond %{REQUEST_FILENAME} !^/mailman
  RewriteCond %{REQUEST_FILENAME} !^/pipermail
  RewriteRule ^(.*)$ /home/stagewww/php/get.php3 [L,NS]
The first three rules are exclusion conditions: URLs starting with /php, /mailman, or /pipermail are passed through so they can be processed by Apache. This is because these URLs are handled by other programs (including PHP itself). The final rule converts the URL into a call to get.php3. (Why is %{QUERY_STRING} not needed here? I have no idea... :-/ ).

The "NS" attached to this rule means "no-subrequest," which means that Apache ignores this rules for internal sub-requests, which is very important and will be explained in part II of this FAQ.