This is a draft cheat sheet. It is a work in progress and is not finished yet.
RewriteRule syntax
RewriteRule Pattern Substitution [flags]
|
RewriteRule substitutions
path |
When rule is configured in server context and file system path does exist |
URL |
A relative path to the resource to be served |
- |
Do not substitute anything |
$N |
Reference to capturing group in RewriteRule
pattern |
%N |
Reference to capturing group in RewriteCond
|
%{VARNAME} |
Server variable |
${map:key|default} |
Mapping function |
RewriteRule flags
B |
Escape non-alphanumerical characters before substitution |
BNP |
Escape space as %20 and not + |
C |
Chain the rules. It this rule fails, the chained one will be skipped |
CO |
Set a cookie |
DPI |
Discard path info of the URL |
END |
Stop all rewriting imeediately |
F |
Return 403 Forbidden |
G |
Return 410 Gone |
H |
Send to specific content handler |
L |
Stop rewriting on this rule |
N |
Re-run rewriting from the first rule |
NC |
Case-insensitive |
NE |
Do not hex-escape special characters |
NS |
Skip rule if it's a subrequest |
P |
PT |
QSA |
Add query string |
QSD |
Discard query string |
QSL |
Treat the last ? as QS delimiter |
R |
Redirect with code |
S |
Skip next N rules |
T |
Set the MIME-type |
Multiple flags should be comma-separated
|
|
Logging
mod_rewrite
logging can be enabled in apache configuration file with LogLevel
directive. Possible levels are from trace1
to trace8
. Log levels higher than 2 should be used only for debugging.
Config example:
LogLevel alert rewrite:trace3
|
Directives
RewriteBase |
specifies the URL prefix to be used for per-directory (htaccess) RewriteRule
directives that substitute a relative path |
RewriteCond |
These directives may precede RewriteRule
. For rule that matches URL it will trigger rewriting only if all it's conditions evaluate to true |
RewriteEngine |
Enable or disable rewriting |
RewriteMap |
Used for values mapping in substitutions of RewriteRule
. Map values from files, databases, external functions etc. |
RewriteOptions |
Specifies rewriting options for server of directory |
RewriteRule |
Manch the URL, make substitution(s). This directive only used for matching against URL path. For matching port, scheme, query string use RewriteCond
|
|