-
Notifications
You must be signed in to change notification settings - Fork 5
Internals
tkb-github edited this page Jun 26, 2024
·
4 revisions
A major difference between mod_setenvif
and mod_rewrite
lies in how they deal with multiple backslashes in regex.
mod_rewrite
has its own parser (‘what an inclined parser’!):
/*
* determine second argument
*/
quote = (*str == '"' || *str == '\'') ? *str++ : '\0';
*a2 = str;
for (; *str; ++str) {
if ((apr_isspace(*str) && !quote) || (*str == quote)) {
break;
}
if (*str == '\\' && apr_isspace(str[1])) {
++str;
continue;
}
}
mod_setenvif
, by contrast, relies on ap_getword_conf
, which strips out every other backslash:
for (i = 0; i < len; ++i) {
if (start[i] == '\\' && (start[i + 1] == '\\'
|| (quote && start[i + 1] == quote)))
*resp++ = start[++i];
else
*resp++ = start[i];
}
To counter this effect, nG-SetEnvIf uses more backslashes than upstream.
mod_rewrite
should be considered a last resort, when other alternatives are found wanting. Using it when there are simpler alternatives leads to configurations which are confusing, fragile, and hard to maintain. Understanding what other alternatives are available is a very important step towards mod_rewrite
mastery
— Rich Bowen