RewriteRule
RewriteRulePattern Substitution
[flags
] Server config, virtual host, directory
This directive can be used as many times as
necessary. Each occurrence applies the rule to the output of the
preceding one, so the order matters.
Pattern
is matched to
the incoming URL; if it succeeds, the
Substitution
is made. An optional
argument, flags
, can
be given. The flags, which follow, can be abbreviated to one or two
letters:
redirect|R
Force redirect.
proxy|P
Force proxy.
last|L
Last rule — go to top of rule with current URL.
chain|C
Apply following chained rule if this rule matches.
type|T=
mime-type
Force target file to be mime-type.
nosubreq|NS
Skip rule if it is an internal subrequest.
env|E=VAR:VAL
Set an environment variable.
qsappend|QSA
Append a query string.
passthrough|PT
Pass through to next handler.
skip|S=
num
Skip the next num
rules.
next|N
Next round — start at the top of the rules again.
gone|G
Returns HTTP response 410 — “URL Gone.”
forbidden|F
Returns HTTP response 403 — “URL Forbidden.”
nocase|NC
Makes the comparison case insensitive.
For example, say we want to rewrite URLs of the form:
/Language/~Realname/.../File
into:
/u/Username/.../File.Language
We take the rewrite map file and save it under /anywhere/map.real-to-user. Then we only have to add the following lines to the Apache server Config file:
RewriteLog /anywhere/rewrite.log RewriteMap real-to-user txt:/anywhere/map.real-to-host RewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1