From: Rich Bowen $N
in the substitution string!
[QSA]
flag.
Additionally you can set special actions to be performed by
+ id="rewriteflags">actions to be performed by
appending [
flags]
as the third argument to the RewriteRule
- directive. Flags is a comma-separated list, surround by square
- brackets, of any of the following flags:
B
' (escape backreferences)Apache has to unescape URLs before mapping them, - so backreferences will be unescaped at the time they are applied. - Using the B flag, non-alphanumeric characters in backreferences - will be escaped. For example, consider the rule:
- RewriteRule ^(.*)$ index.php?show=$1
- This will map /C++
to index.php?show=/C++
.
- But it will also map /C%2b%2b
to
- index.php?show=/C++
, because the %2b
- has been unescaped. With the B flag, it will instead map to
- index.php?show=/C%2b%2b
.
This escaping is particularly necessary in a proxy situation, - when the backend may break if presented with an unescaped URL.
-chain|C
'
- (chained with next rule).www
'' part, inside a per-directory rule set,
- when you let an external redirect happen (where the
- ``.www
'' part should not occur!).cookie|CO=
NAME:VAL:domain[:lifetime[:path[:secure[:httponly]]]]'
- (set cookie)HttpOnly
flag is used, making the cookie not accessible
- to JavaScript code on browsers that support this feature.discardpathinfo|DPI'
- (discard PATH_INFO)
In per-directory context, the URI each
The current URI can be the initial URI as requested by the client, the - result of a previous round of mod_rewrite processing, or the result of - a prior rule in the current round of mod_rewrite processing.
- -In contrast, the PATH_INFO that is appended to the URI before each
- rule reflects only the value of PATH_INFO before this round of
- mod_rewrite processing. As a consequence, if large portions
- of the URI are matched and copied into a substitution in multiple
-
Use this flag on any substitution where the PATH_INFO that resulted - from the previous mapping of this request to the filesystem is not of - interest. This flag permanently forgets the PATH_INFO established - before this round of mod_rewrite processing began. PATH_INFO will - not be recalculated until the current round of mod_rewrite processing - completes. Subsequent rules during this round of processing will see - only the direct result of substitutions, without any PATH_INFO - appended.
env|E=!
VAR[:VAL]'
- (set environment variable)$N
and
- %N
) which will be expanded. The form !VAR causes
- the environment variable VAR to be unset and does not accept
- any VAL. You can use this flag more than once, to set more
- than one variable. The variables can later be dereferenced in many
- situations, most commonly from within XSSI (via <!--#echo
- var="VAR"-->
) or CGI ($ENV{'VAR'}
).
- You can also dereference the variable in a later RewriteCond pattern, using
- %{ENV:VAR}
. Use this to strip
- information from URLs, while maintaining a record of that information.forbidden|F
' (force URL
- to be forbidden)gone|G
' (force URL to be
- gone)handler|H
=Content-handler'
- (force Content handler)cgi-script
''.last|L
'
- (last rule)last
command or the
- break
command in C. Use this flag to prevent the
- currently rewritten URL from being rewritten further by
- following rules. Remember, however, that if the
- next|N
'
- (next round)next
command or
- the continue
command in C. Use
- this flag to restart the rewriting process -
- to immediately go to the top of the loop.
- Be careful not to create an infinite
- loop!nocase|NC
'
- (no case)noescape|NE
'
- (no URI escaping of
- output)/foo/zed
' into a safe
- request for '/bar?arg=P1=zed
'.
- nosubreq|NS
'
- (not for internal
- sub-requests)This flag forces the rewriting engine to skip a
- rewriting rule if the current request is an internal
- sub-request. For instance, sub-requests occur internally
- in Apache when index.xxx
files). On sub-requests it is not
- always useful, and can even cause errors, if
- the complete set of rules are applied. Use this flag to
- exclude some rules.
To decide whether or not to use this rule: if you - prefix URLs with CGI-scripts, to force them to be - processed by the CGI-script, it's likely that you - will run into problems (or significant overhead) on - sub-requests. In these cases, use this flag.
-proxy|P
' (force
- proxy)http://
hostname) which can be
- handled by the Apache proxy module. If not, you will get an
- error from the proxy module. Use this flag to achieve a
- more powerful implementation of the ProxyPass directive,
- to map remote content into the namespace of the local
- server.
-
- Note:
passthrough|PT
'
- (pass through to next
- handler)uri
field of the internal
- request_rec
structure to the value of the
- filename
field. This flag is just a hack to
- enable post-processing of the output of
- RewriteRule
directives, using
- Alias
, ScriptAlias
,
- Redirect
, and other directives from
- various URI-to-filename translators. For example, to rewrite
- /abc
to /def
using
- /def
to /ghi
using
- PT
flag,
- mod_rewrite
will rewrite
- uri=/abc/...
to
- filename=/def/...
as a full API-compliant
- URI-to-filename translator should do. Then
- mod_alias
will try to do a
- URI-to-filename transition, which will fail.
-
- Note: You must use this flag if you want to
- mix directives from different modules which allow
- URL-to-filename translators. The typical example
- is the use of
The PT
flag implies the L
flag:
- rewriting will be stopped in order to pass the request to
- the next phase of processing.
qsappend|QSA
'
- (query string
- append)redirect|R
- [=code]' (force redirect)Prefix Substitution with
- http://thishost[:thisport]/
(which makes the
- new URL a URI) to force a external redirection. If no
- code is given, a HTTP response of 302 (MOVED
- TEMPORARILY) will be returned. If you want to use other
- response codes, simply specify the appropriate number or use
- one of the following symbolic names: temp
- (default), permanent
,
- seeother
. Use this for rules to canonicalize
- the URL and return it to the client - to translate
- ``/~
'' into ``/u/
'', or to always
- append a slash to /u/
user, etc.
- Note: When you use this flag, make sure
- that the substitution field is a valid URL! Otherwise, you
- will be redirecting to an invalid location. Remember that
- this flag on its own will only prepend
- http://thishost[:thisport]/
to the URL, and
- rewriting will continue. Usually, you will want to stop
- rewriting at this point, and redirect immediately. To stop
- rewriting, you should add the 'L' flag.
While this is typically used for redirects, any valid status
- code can be given here. If the status code is outside the redirect
- range (300-399), then the Substitution string is dropped
- and rewriting is stopped as if the L
flag was
- used.
skip|S
=num'
- (skip next rule(s))skip=N
, where N is the number of rules in the
- else-clause. (This is not the same as the
- 'chain|C' flag!)type|T
=MIME-type'
- (force MIME type).php
files to
- be displayed by mod_php
if they are called with
- the .phps
extension:
- Flag and syntax | +Function | +
---|---|
B | +Escape non-alphanumeric characters before applying + the transformation. details ... | +
chain|C | +Rule is chained to the following rule. If the rule fails, + the rule(s) chained to it will be skipped. details ... | +
cookie|CO=NAME:VAL | +Sets a cookie in the client browser. Full syntax is: + CO=NAME:VAL[:domain[:lifetime[:path[:secure[:httponly]]]]] details ... + | +
discardpath|DPI | +Causes the PATH_INFO portion of the rewritten URI to be + discarded. details + ... | +
env|E=[!]VAR[:VAL] | +Causes an environment variable VAR to be set (to the + value VAL if provided). The form !VAR causes + the environment variable VAR to be unset.details ... | +
forbidden|F | +Returns a 403 FORBIDDEN response to the client browser. + details ... | +
gone|G | +Returns a 410 GONE response to the client browser. details ... | +
Handler|H=Content-handler | +Causes the resulting URI to be sent to the specified + Content-handler for processing. details ... | +
last|L | +Stop the rewriting process immediately and don't apply any + more rules. Especially note caveats for per-directory and + .htaccess context (see also the END flag). details ... | +
next|N | +Re-run the rewriting process, starting again with the first + rule, using the result of the ruleset so far as a starting + point. details + ... | +
nocase|NC | +Makes the pattern pattern comparison case-insensitive. + details ... | +
noescape|NE | +Prevent mod_rewrite from applying hexcode escaping of + special characters in the result of the rewrite. details ... | +
nosubreq|NS | +Causes a rule to be skipped if the current request is an + internal sub-request. details ... | +
proxy|P | +Force the substitution URL to be internally sent as a proxy + request. details + ... | +
passthrough|PT | +Forces the resulting URI to be passed back to the URL
+ mapping engine for processing of other URI-to-filename
+ translators, such as Alias or
+ Redirect . details ... |
+
qsappend|QSA | +Appends any query string created in the rewrite target to + any query string that was in the original request URL. details ... | +
redirect|R[=code] | +Forces an external redirect, optionally with the specified + HTTP status code. details ... + | +
skip|S=num | +Tells the rewriting engine to skip the next num + rules if the current rule matches. details ... | +
type|T=MIME-type | +Force the |
+
When the substitution string begins with a string