Apache Reference: mod_rewrite, RewriteRule

RewriteRule

Rewrite Rule
Syntax: RewriteRule url-pattern url-new [[flag,...]]
Example: RewriteRule ^/foo/(.*)$ /bar/$1 [R,L]
Since: Apache 1.2

This directive is the real rewriting workhorse. It can occur more than once. Each directive then defines a single rewriting rule. The definition order of these rules is important, because it is used when applying the rules at runtime. The url-pattern is a regular expression that is applied to the current URL, where ``current'' means at the time when this rule is applied. The current URL may not be the original requested URL, because any number of rules could have already matched and altered it.

The url-new argument is the string that is substituted for the original URL matched by the url-pattern. Beside plain text, you can use back-references ($N) to the url-pattern, back- references (%N) to the last matched RewriteCond pattern, server variables such as RewriteCond test strings (%{NAME}), and mapping function calls (${map-name:look==up-key|default-value}) for this argument.

In addition, you can set special flags for url-new by appending one or more flag arguments. The flag argument is actually a comma-separated list of the following flags: redirect (or R) to force an HTTP redirect; forbidden (or F) to forbid access; gone (or G) to eliminate the URL; proxy (or P) to pass the URL to mod_proxy; last (or L) to stop processing; next (or N) to start the next round of processing; chain (or C) to chain the current rule with the following one; type (or T) to force a particular MIME type; nosubreq (or NS) to ensure that the rule applies only if no internal sub-request is performed; nocase (or NC) to force the URL matching to be case-insensitive; qsappend (or QSA) to append a query string part in url-new to the existing one instead of replacing it; passthrough (or PT) to pass the rewritten URL through to other Apache modules; skip (or S) to skip the next rule; and env (or E) to set an environment variable. For more details, see the mod_rewrite online documentation.