gnif/mod_rpaf — Issue #6: Compatibility with RewriteCond %{HTTPS}
Author: jonmz
Created: 2012-02-16 00:21:42+00:00
State: open

Apache sets a special "HTTPS" flag which can be used in RewriteCond statements as %{HTTPS}. The [RewriteCond docs](http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond) tell about it:

> HTTPS
> Will contain the text "on" if the connection is using SSL/TLS, or "off" otherwise. (This variable can be safely used regardless of whether or not mod_ssl is loaded).

mod_rpaf can already set the "HTTPS" environment variable which is working fine, but you have to use %{ENV:HTTPS} to access it in a RewriteCond. This is from the Apache source, `modules/mappers/mod_rewrite.c`:

case 5:
if (!strcmp(var, "HTTPS")) {
int flag = rewrite_is_https && rewrite_is_https(r->connection);
return apr_pstrdup(r->pool, flag ? "on" : "off");
}
break;

As you can see, mod_rewrite isn't looking at the HTTPS environment variable but on a special function `rewrite_is_https` which in turn seems to be based on a `ssl_is_https` function provided by `mod_ssl`. (Please forgive me, I'm no C programmer so this is only a very loose interpretation of the Apache source code.)

There are plenty of mod_rewrite examples in the wild which are based on %{HTTPS}. It would be really nice if mod_rpaf could "somehow" provide support for setting it. Currently %{HTTPS} provides the value 'off' while %{ENV:HTTPS} correctly provides 'on'.