]> granicus.if.org Git - apache/commitdiff
Fix LA-U and LA-F lookups in directory context. Previously
authorAndré Malo <nd@apache.org>
Tue, 19 Aug 2003 00:36:58 +0000 (00:36 +0000)
committerAndré Malo <nd@apache.org>
Tue, 19 Aug 2003 00:36:58 +0000 (00:36 +0000)
the current rewrite state was just used as lookup path, which lead to
strange and often useless results.

Related to PR 8493.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@101011 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/mappers/mod_rewrite.c

diff --git a/CHANGES b/CHANGES
index 111fa74c37f5c5439447bf538b1da62bc41c90db..0d9ac72615865020f0aa0ad9299bfb90360da520 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,10 @@ Changes with Apache 2.1.0-dev
 
   [Remove entries to the current 2.0 section below, when backported]
 
+  *) mod_rewrite: Fix LA-U and LA-F lookups in directory context. Previously
+     the current rewrite state was just used as lookup path, which lead to
+     strange and often useless results. Related to PR 8493.  [André Malo]
+
   *) Change Listen directive to bind to all addresses when a hostname is
      not specified.  [Justin Erenkrantz]
 
index bc55cea1135cadcd6e54f971683236aa244dbdb2..932121f8d768b17d37186c964cbd48c1859db850 100644 (file)
@@ -1583,6 +1583,25 @@ static const char *lookup_header(request_rec *r, const char *name)
     return val;
 }
 
+/*
+ * lookahead helper function
+ * Determine the correct URI path in perdir context
+ */
+static APR_INLINE const char *la_u(exp_ctx *ctx)
+{
+    rewrite_perdir_conf *conf;
+
+    if (*ctx->uri == '/') {
+        return ctx->uri;
+    }
+
+    conf = ap_get_module_config(ctx->r->per_dir_config, &rewrite_module);
+
+    return apr_pstrcat(ctx->r->pool, conf->baseurl
+                                     ? conf->baseurl : conf->directory,
+                       ctx->uri, NULL);
+}
+
 /*
  * generic variable lookup
  */
@@ -1616,34 +1635,57 @@ static char *lookup_variable(char *var, exp_ctx *ctx)
     else if (var[4] == ':') {
         if (var[5]) {
             request_rec *rr;
+            const char *path;
 
             if (!strncasecmp(var, "HTTP", 4)) {
                 result = lookup_header(r, var+5);
             }
             else if (!strncasecmp(var, "LA-U", 4)) {
-                if (r->filename && subreq_ok(r)) {
-                    rr = ap_sub_req_lookup_uri(ctx->uri, r, NULL);
+                if (ctx->uri && subreq_ok(r)) {
+                    path = ctx->perdir ? la_u(ctx) : ctx->uri;
+                    rr = ap_sub_req_lookup_uri(path, r, NULL);
                     ctx->r = rr;
                     result = apr_pstrdup(r->pool, lookup_variable(var+5, ctx));
                     ctx->r = r;
                     ap_destroy_sub_req(rr);
 
-                    rewritelog((r, 5, NULL,"lookahead: path=%s var=%s -> val=%s",
-                                r->filename, var+5, result));
+                    rewritelog((r, 5, ctx->perdir, "lookahead: path=%s var=%s "
+                                "-> val=%s", path, var+5, result));
 
                     return (char *)result;
                 }
             }
             else if (!strncasecmp(var, "LA-F", 4)) {
-                if (r->filename && subreq_ok(r)) {
-                    rr = ap_sub_req_lookup_file(ctx->uri, r, NULL);
+                if (ctx->uri && subreq_ok(r)) {
+                    path = ctx->uri;
+                    if (ctx->perdir && *path == '/') {
+                        /* sigh, the user wants a file based subrequest, but
+                         * we can't do one, since we don't know what the file
+                         * path is! In this case behave like LA-U.
+                         */
+                        rr = ap_sub_req_lookup_uri(path, r, NULL);
+                    }
+                    else {
+                        if (ctx->perdir) {
+                            rewrite_perdir_conf *conf;
+
+                            conf = ap_get_module_config(r->per_dir_config,
+                                                        &rewrite_module);
+
+                            path = apr_pstrcat(r->pool, conf->directory, path,
+                                               NULL);
+                        }
+
+                        rr = ap_sub_req_lookup_file(path, r, NULL);
+                    }
+
                     ctx->r = rr;
                     result = apr_pstrdup(r->pool, lookup_variable(var+5, ctx));
                     ctx->r = r;
                     ap_destroy_sub_req(rr);
 
-                    rewritelog((r, 5, NULL,"lookahead: path=%s var=%s -> val=%s",
-                                r->filename, var+5, result));
+                    rewritelog((r, 5, ctx->perdir, "lookahead: path=%s var=%s "
+                                "-> val=%s", path, var+5, result));
 
                     return (char *)result;
                 }
@@ -1668,7 +1710,7 @@ static char *lookup_variable(char *var, exp_ctx *ctx)
                 result = apr_psprintf(r->pool, "%04d%02d%02d%02d%02d%02d",
                                       tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
                                       tm.tm_hour, tm.tm_min, tm.tm_sec);
-                rewritelog((r, 1, NULL, "RESULT='%s'", result));
+                rewritelog((r, 1, ctx->perdir, "RESULT='%s'", result));
                 return (char *)result;
             }
             break;