• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

19.34. 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 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 string condition

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

(Apache 1.3 or later)


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

(Apache 1.2 or later)


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.

(Apache 1.3 or later)


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"

(Apache 1.2 or later)


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.

(Apache 1.2 or later)


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:


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


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


The source variable points to a DBM-formatted file


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


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

(Apache 1.3 or later)


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:


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

(Apache 1.2 or later)


RewriteRule pattern substitution

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

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

(Apache 1.3 or later)



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint