Directives provided by mod-rewrite in Apache 2.4

Other topics

List of directives available in Apache 2.4

Apache 2.4 provides the following 6 directives via the mod_rewrite module:

  1. RewriteBase
  2. RewriteCond
  3. RewriteEngine
  4. RewriteMap
  5. RewriteOptions
  6. RewriteRule

The following directives, available previously in Apache 2.2 have been removed:

  1. RewriteLock
  2. RewriteLog
  3. RewriteLogLevel

All the directives (with the exception of RewriteMap) defined by mod_rewrite can be allowed to override on a per-directory .htaccess through the AllowOverride FileInfo.

DirectiveContextDescription
RewriteBasedirectory, .htaccessSets base URL for per directory rewrite
RewriteCondEverywhereDefines conditions under which the rewrite action will occur
RewriteEngineEverywhereSets status of rewrite engine
RewriteMapserver config, virtual hostDefines a key lookup function
RewriteOptionsEverywhereSets special options for rewrite engine
RewriteRuleEverywhereDefines specific rules for rewrite engine

The context Everwhere means that the directive can be defined in any of the following four locations:

  1. server config
  2. virtual host config
  3. directory context
  4. .htaccess file

The RewriteLog and RewriteLogLevel directives have been merged with the global LogLevel directive and would be used as:

LogLevel rewrite:<level>

where <level> is a value from trace8 (least significant) to emerg (most significant). This list is available here.

RewriteBase and RewriteEngine

DirectiveDefaultContextDescription
RewriteBaseNoneDirectory, .htaccessSets base URL for per directory rewrite
RewriteEngineoffeverywhereEnable or disable runtime rewrite engine

RewriteBase

The directive specifies URL prefix to be used for substituting relative paths.

RewriteEngine

The directive, if set to off, will perform no runtime rewrite processing. These rules are not inherited by the virtual hosts (from server config), and will have to be defined individually.

RewriteMap

The directive defines a function which'll lookup a key in the defined map and substitutes the lookup with its replacement from the map.

The mapping function is defined with the RewriteMap directive itself as follows:

RewriteMap MAPNAME Type:Source

and can be referenced in any of the RewriteCond or RewriteRule directives to act as a substitution guide as follows:

${ MAPNAME : KEY | DEFAULT }

The following are valid values for Type in the map definition:

  1. int - allows toupper, tolower, escape and unescape only
  2. txt - searches a text file
  3. dbd - looks up in a database using SQL SELECT statement
  4. rnd - random lookups from text file
  5. dbm - similar to txt, except that the httxt2dbm needs to convert the data to hashes
  6. fastdbd - looks up in a database using SQL SELECT statement with caching

Syntax:

  • RewriteBase URL-path
  • RewriteCond TestString CondPattern
  • RewriteEngine on|off
  • RewriteMap MapName MapType:MapSource
  • RewriteOptions Options
  • RewriteRule Pattern Substitution [flags]

Contributors

Topic Id: 5981

Example Ids: 20928,20929,20930

This site is not affiliated with any of the contributors.