7f6d46
diff --git a/include/ap_regex.h b/include/ap_regex.h
7f6d46
index 5122154..349ae83 100644
7f6d46
--- a/include/ap_regex.h
7f6d46
+++ b/include/ap_regex.h
7f6d46
@@ -77,6 +77,8 @@ extern "C" {
7f6d46
 #define AP_REG_NOMEM 0x20    /* nomem in our code */
7f6d46
 #define AP_REG_DOTALL 0x40   /* perl's /s flag */
7f6d46
 
7f6d46
+#define AP_REG_DOLLAR_ENDONLY 0x200 /**< '$' matches at end of subject string only */
7f6d46
+
7f6d46
 /* Error values: */
7f6d46
 enum {
7f6d46
   AP_REG_ASSERT = 1,  /** internal error ? */
7f6d46
@@ -100,6 +102,26 @@ typedef struct {
7f6d46
 
7f6d46
 /* The functions */
7f6d46
 
7f6d46
+/**
7f6d46
+ * Get default compile flags
7f6d46
+ * @return Bitwise OR of AP_REG_* flags
7f6d46
+ */
7f6d46
+AP_DECLARE(int) ap_regcomp_get_default_cflags(void);
7f6d46
+
7f6d46
+/**
7f6d46
+ * Set default compile flags
7f6d46
+ * @param cflags Bitwise OR of AP_REG_* flags
7f6d46
+ */
7f6d46
+AP_DECLARE(void) ap_regcomp_set_default_cflags(int cflags);
7f6d46
+
7f6d46
+/**
7f6d46
+ * Get the AP_REG_* corresponding to the string.
7f6d46
+ * @param name The name (i.e. AP_REG_<name>)
7f6d46
+ * @return The AP_REG_*, or zero if the string is unknown
7f6d46
+ *
7f6d46
+ */
7f6d46
+AP_DECLARE(int) ap_regcomp_default_cflag_by_name(const char *name);
7f6d46
+
7f6d46
 /**
7f6d46
  * Compile a regular expression.
7f6d46
  * @param preg Returned compiled regex
7f6d46
diff --git a/server/core.c b/server/core.c
7f6d46
index b3240a0..e073ddf 100644
7f6d46
--- a/server/core.c
7f6d46
+++ b/server/core.c
7f6d46
@@ -48,6 +48,7 @@
7f6d46
 #include "mod_core.h"
7f6d46
 #include "mod_proxy.h"
7f6d46
 #include "ap_listen.h"
7f6d46
+#include "ap_regex.h"
7f6d46
 
7f6d46
 #include "mod_so.h" /* for ap_find_loaded_module_symbol */
7f6d46
 
7f6d46
@@ -2646,6 +2647,58 @@ static const char *virtualhost_section(cmd_parms *cmd, void *dummy,
7f6d46
     return errmsg;
7f6d46
 }
7f6d46
 
7f6d46
+static const char *set_regex_default_options(cmd_parms *cmd,
7f6d46
+                                             void *dummy,
7f6d46
+                                             const char *arg)
7f6d46
+{
7f6d46
+    const command_rec *thiscmd = cmd->cmd;
7f6d46
+    int cflags, cflag;
7f6d46
+
7f6d46
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
7f6d46
+    if (err != NULL) {
7f6d46
+        return err;
7f6d46
+    }
7f6d46
+
7f6d46
+    cflags = ap_regcomp_get_default_cflags();
7f6d46
+    while (*arg) {
7f6d46
+        const char *name = ap_getword_conf(cmd->pool, &arg;;
7f6d46
+        int how = 0;
7f6d46
+
7f6d46
+        if (strcasecmp(name, "none") == 0) {
7f6d46
+            cflags = 0;
7f6d46
+            continue;
7f6d46
+        }
7f6d46
+
7f6d46
+        if (*name == '+') {
7f6d46
+            name++;
7f6d46
+            how = +1;
7f6d46
+        }
7f6d46
+        else if (*name == '-') {
7f6d46
+            name++;
7f6d46
+            how = -1;
7f6d46
+        }
7f6d46
+
7f6d46
+        cflag = ap_regcomp_default_cflag_by_name(name);
7f6d46
+        if (!cflag) {
7f6d46
+            return apr_psprintf(cmd->pool, "%s: option '%s' unknown",
7f6d46
+                                thiscmd->name, name);
7f6d46
+        }
7f6d46
+
7f6d46
+        if (how > 0) {
7f6d46
+            cflags |= cflag;
7f6d46
+        }
7f6d46
+        else if (how < 0) {
7f6d46
+            cflags &= ~cflag;
7f6d46
+        }
7f6d46
+        else {
7f6d46
+            cflags = cflag;
7f6d46
+        }
7f6d46
+    }
7f6d46
+    ap_regcomp_set_default_cflags(cflags);
7f6d46
+
7f6d46
+    return NULL;
7f6d46
+}
7f6d46
+
7f6d46
 static const char *set_server_alias(cmd_parms *cmd, void *dummy,
7f6d46
                                     const char *arg)
7f6d46
 {
7f6d46
@@ -4164,6 +4217,9 @@ AP_INIT_TAKE12("RLimitNPROC", no_set_limit, NULL,
7f6d46
    OR_ALL, "soft/hard limits for max number of processes per uid"),
7f6d46
 #endif
7f6d46
 
7f6d46
+AP_INIT_RAW_ARGS("RegexDefaultOptions", set_regex_default_options, NULL, RSRC_CONF,
7f6d46
+                 "default options for regexes (prefixed by '+' to add, '-' to del)"),
7f6d46
+
7f6d46
 /* internal recursion stopper */
7f6d46
 AP_INIT_TAKE12("LimitInternalRecursion", set_recursion_limit, NULL, RSRC_CONF,
7f6d46
               "maximum recursion depth of internal redirects and subrequests"),
7f6d46
@@ -4569,6 +4625,8 @@ static int core_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptem
7f6d46
     apr_pool_cleanup_register(pconf, NULL, reset_config_defines,
7f6d46
                               apr_pool_cleanup_null);
7f6d46
 
7f6d46
+    ap_regcomp_set_default_cflags(AP_REG_DOLLAR_ENDONLY);
7f6d46
+
7f6d46
     mpm_common_pre_config(pconf);
7f6d46
 
7f6d46
     return OK;
7f6d46
diff --git a/server/util_pcre.c b/server/util_pcre.c
7f6d46
index 1e83cad..d7df400 100644
7f6d46
--- a/server/util_pcre.c
7f6d46
+++ b/server/util_pcre.c
7f6d46
@@ -110,6 +110,38 @@ AP_DECLARE(void) ap_regfree(ap_regex_t *preg)
7f6d46
  *            Compile a regular expression       *
7f6d46
  *************************************************/
7f6d46
 
7f6d46
+static int default_cflags = AP_REG_DOLLAR_ENDONLY;
7f6d46
+
7f6d46
+AP_DECLARE(int) ap_regcomp_get_default_cflags(void)
7f6d46
+{
7f6d46
+    return default_cflags;
7f6d46
+}
7f6d46
+
7f6d46
+AP_DECLARE(void) ap_regcomp_set_default_cflags(int cflags)
7f6d46
+{
7f6d46
+    default_cflags = cflags;
7f6d46
+}
7f6d46
+
7f6d46
+AP_DECLARE(int) ap_regcomp_default_cflag_by_name(const char *name)
7f6d46
+{
7f6d46
+    int cflag = 0;
7f6d46
+
7f6d46
+    if (strcasecmp(name, "ICASE") == 0) {
7f6d46
+        cflag = AP_REG_ICASE;
7f6d46
+    }
7f6d46
+    else if (strcasecmp(name, "DOTALL") == 0) {
7f6d46
+        cflag = AP_REG_DOTALL;
7f6d46
+    }
7f6d46
+    else if (strcasecmp(name, "DOLLAR_ENDONLY") == 0) {
7f6d46
+        cflag = AP_REG_DOLLAR_ENDONLY;
7f6d46
+    }
7f6d46
+    else if (strcasecmp(name, "EXTENDED") == 0) {
7f6d46
+        cflag = AP_REG_EXTENDED;
7f6d46
+    }
7f6d46
+
7f6d46
+    return cflag;
7f6d46
+}
7f6d46
+
7f6d46
 /*
7f6d46
  * Arguments:
7f6d46
  *  preg        points to a structure for recording the compiled expression
7f6d46
@@ -126,12 +158,16 @@ AP_DECLARE(int) ap_regcomp(ap_regex_t * preg, const char *pattern, int cflags)
7f6d46
     int errcode = 0;
7f6d46
     int options = 0;
7f6d46
 
7f6d46
+    cflags |= default_cflags;
7f6d46
     if ((cflags & AP_REG_ICASE) != 0)
7f6d46
         options |= PCRE_CASELESS;
7f6d46
     if ((cflags & AP_REG_NEWLINE) != 0)
7f6d46
         options |= PCRE_MULTILINE;
7f6d46
     if ((cflags & AP_REG_DOTALL) != 0)
7f6d46
         options |= PCRE_DOTALL;
7f6d46
+    if ((cflags & AP_REG_DOLLAR_ENDONLY) != 0)
7f6d46
+        options |= PCRE_DOLLAR_ENDONLY;
7f6d46
+
7f6d46
 
7f6d46
     preg->re_pcre =
7f6d46
         pcre_compile2(pattern, options, &errcode, &errorptr, &erroffset, NULL);