Apache 2.4 provides the following 6 directives via the mod_rewrite
module:
The following directives, available previously in Apache 2.2 have been removed:
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
.
Directive | Context | Description |
---|---|---|
RewriteBase | directory, .htaccess | Sets base URL for per directory rewrite |
RewriteCond | Everywhere | Defines conditions under which the rewrite action will occur |
RewriteEngine | Everywhere | Sets status of rewrite engine |
RewriteMap | server config, virtual host | Defines a key lookup function |
RewriteOptions | Everywhere | Sets special options for rewrite engine |
RewriteRule | Everywhere | Defines specific rules for rewrite engine |
The context Everwhere
means that the directive can be defined in any of the following four locations:
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.
Directive | Default | Context | Description |
---|---|---|---|
RewriteBase | None | Directory, .htaccess | Sets base URL for per directory rewrite |
RewriteEngine | off | everywhere | Enable 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.
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:
int
- allows toupper
, tolower
, escape
and unescape
onlytxt
- searches a text filedbd
- looks up in a database using SQL SELECT
statementrnd
- random lookups from text filedbm
- similar to txt
, except that the httxt2dbm
needs to convert the data to hashesfastdbd
- looks up in a database using SQL SELECT
statement with caching