From: Rainer Jung $N
in the substitution string!
only the direct result of substitutions, without any PATH_INFO
appended.
env|E=
VAR[:VAL]'
+ env|E=!
VAR[:VAL]'
(set environment variable)$N
and
- %N
) which will be expanded. 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
+ %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
diff --git a/docs/manual/rewrite/rewrite_flags.xml b/docs/manual/rewrite/rewrite_flags.xml
index ae2b97f9f47..2d11ec93186 100644
--- a/docs/manual/rewrite/rewrite_flags.xml
+++ b/docs/manual/rewrite/rewrite_flags.xml
@@ -108,7 +108,39 @@ is run, thus unsetting what you have set. See the
Environment Variables document for more details on how Environment
variables work.
-The following example sets an evironment variable called 'image' to a
+
The full syntax for this flag is:
+
+
+[E=VAR:VAL]
+[E=!VAR]
+
+
+VAL
may contain backreferences ($N
or
+%N
) which will be expanded.
+
+Using the short form
+
+
+[E=VAR]
+
+
+you can set the environment variable named VAR
to an
+empty value.
+
+The form
+
+
+[E=!VAR]
+
+
+allows to unset a previously set environment variable named
+VAR
.
+
+Environment variables can then be used in a variety of
+contexts, including CGI programs, other RewriteRule directives, or
+CustomLog directives.
+
+The following example sets an environment variable called 'image' to a
value of '1' if the requested URI is an image file. Then, that
environment variable is used to exclude those requests from the access
log.
diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c
index 36609ccaa94..700107385f2 100644
--- a/modules/mappers/mod_rewrite.c
+++ b/modules/mappers/mod_rewrite.c
@@ -2347,15 +2347,22 @@ static void do_expand_env(data_item *env, rewrite_ctx *ctx)
while (env) {
name = do_expand(env->data, ctx, NULL);
- if ((val = ap_strchr(name, ':')) != NULL) {
- *val++ = '\0';
- } else {
- val = "";
+ if (*name == '!') {
+ name++;
+ apr_table_unset(ctx->r->subprocess_env, name);
+ rewritelog((ctx->r, 5, NULL, "unsetting env variable '%s'", name));
}
+ else {
+ if ((val = ap_strchr(name, ':')) != NULL) {
+ *val++ = '\0';
+ } else {
+ val = "";
+ }
- apr_table_set(ctx->r->subprocess_env, name, val);
- rewritelog((ctx->r, 5, NULL, "setting env variable '%s' to '%s'",
- name, val));
+ apr_table_set(ctx->r->subprocess_env, name, val);
+ rewritelog((ctx->r, 5, NULL, "setting env variable '%s' to '%s'",
+ name, val));
+ }
env = env->next;
}