1

When the following SetEnvIf directive is in a virtual host directory section or in an .htaccess file the Request_URI variable is percent decoded. But when it is not in a directory section or .htaccess file (i.e. virtual host or server config context) it is not decoded (it remains percent encoded).

What controls/determines this difference? My guess is that this is a byproduct of having to traverse the file system directory tree. Because the file system path is not percent encoded.

Is this configurable such that the Request_URI Apache SetEnvIf variable is percent decoded in the virtual host and/or server config context also?

SetEnvIf Request_URI "^.*access_logger/counters/(.*)\.gif$" Page_Name_File_Name=$1 log_file log_sql_db validate_cache

Apache/2.4.6 (CentOS)
Apr 2 2020 13:13:23

1 Answer 1

0

My guess is that this is a byproduct of having to traverse the file system directory tree.

This is a reasonable "guess" since the directives in a server/virtualhost context are processed before the request is mapped to the filesystem.

However, the same does not apply to the REQUEST_URI (same name, but different) server variable as used by mod_rewrite and Apache expressions. This is always %-decoded, regardless of which context it is being used. The same applies to the URL-path matched by the RewriteRule directive, which is always %-decoded, regardless of context.

Is this configurable such that the Request_URI Apache SetEnvIf variable is percent decoded in the virtual host and/or server config context also?

Not that I'm aware. This would seem to be a "feature" of mod_setenvif. (Perhaps due to the specific phases in which the module is processed?)

However, you can use mod_rewrite to set the environment variable instead (or as well as). For example:

RewriteEngine On

RewriteRule access_logger/counters(.*)\.gif$ - [E=Page_Name_File_Name:$1]

The ^.* prefix on the regex is superfluous in this instance.

To set all the environment variables, as per the original SetEnvIf directive, you'll need to explicitly set the remaining vars to 1. For example:

RewriteRule access_logger/counters(.*)\.gif$ - [E=Page_Name_File_Name:$1,E=log_file:1,E=log_sql_db:1,E=validate_cache:1]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .