Book HomeWebmaster in a Nutshell, 3rd EditionSearch this book

19.28. mod_rewrite

The mod_rewrite module allows for rewriting URLs for clients based on specific rules. This is a powerful module with many rewriting features (too many to list here) that perform their functions on the fly.

RewriteBase

RewriteBase url

[Within <Directory> or .htaccess]

Sets the base directory for rewrites. This specifies a portion of the URI that will not be modified by any subsequent rewriting, even if the URI maps to a different filesystem. For example:

RewriteBase /files

This directive tells the rewriting engine to ignore the files directory in the URI when rewriting.

RewriteCond

RewriteCond string condition

Defines a rule condition for URI rewriting. See the Apache documentation for more information.

RewriteEngine

RewriteEngine on|off

[server config, within <Directory> or <VirtualHost>, or .htaccess]

This directive enables or disables the rewriting engine of this module. The default setting is:

RewriteEngine off
RewriteLock

RewriteLock filename

[server config or <VirtualHost>]

Sets a filename to serve as the lockfile used by the rewriting engine. It is recommended that this file reside on the local drive and not on an NFS-mounted drive.

RewriteLog

RewriteLog filename

[server config or <VirtualHost>]

This directive specifies the name of the log file to which it records any URL rewriting activities. filename can be a fully qualified filename or relative to the ServerRoot directive. For example:

RewriteLog "logs/rewrite.log"
RewriteLogLevel

RewriteLogLevel level

[server config or <VirtualHost>]

Sets the amount of reporting that is done to the rewriting log file, a number between 0 and 9. The default is RewriteLogLevel 0. For example:

RewriteLogLevel 3

It is recommended that levels greater than 2 be used only for debugging purposes, as they can generate large amounts of data in a short period of time.

RewriteMap

RewriteMap name type:source

[server config or <VirtualHost>]

Declares the rewriting map and its type. The map file performs substitutions for various URIs. The name parameter makes up the given name of the mapping. The type and source variables are determined by the type:

txt
A plain-text file, with the source pointing to a regular file

rnd
A plain-text file with a random mapping choice; the source variable points to a regular file

dbm
The source variable points to a DBM-formatted file

int
An internal Apache function; the source variable can be one of two functions: toupper or tolower

prg
A program. The source variable points to a Unix executable

Here is an example that shows how to use a text-based rewriting file:

RewriteMap real-host txt:/usr/local/maps/mymap.txt
RewriteOptions

RewriteOptions option

[server config, within <VirtualHost> or <Directory>, or .htaccess]

Sets options for the rewriting engine in this context. Currently, the only option available is:

inherit
This option instructs the current rewriting configuration to inherit the values of its parent directory's access control file.

RewriteRule

RewriteRule pattern substitution

[server config, within <VirtualHost> or <Directory>, or .htaccess]

Defines a single rewriting rule. See the Apache documentation for further information.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.