295152
diff --git a/server/request.c b/server/request.c
295152
index d5c558a..18625af 100644
295152
--- a/server/request.c
295152
+++ b/server/request.c
295152
@@ -1419,7 +1419,20 @@ AP_DECLARE(int) ap_location_walk(request_rec *r)
295152
 
295152
     cache = prep_walk_cache(AP_NOTE_LOCATION_WALK, r);
295152
     cached = (cache->cached != NULL);
295152
-    entry_uri = r->uri;
295152
+
295152
+   /*
295152
+    * When merge_slashes is set to AP_CORE_CONFIG_OFF the slashes in r->uri
295152
+    * have not been merged. But for Location walks we always go with merged
295152
+    * slashes no matter what merge_slashes is set to.
295152
+    */
295152
+    if (sconf->merge_slashes != AP_CORE_CONFIG_OFF) {
295152
+        entry_uri = r->uri;
295152
+    }
295152
+    else {
295152
+        char *uri = apr_pstrdup(r->pool, r->uri);
295152
+        ap_no2slash(uri);
295152
+        entry_uri = uri;
295152
+    }
295152
 
295152
     /* If we have an cache->cached location that matches r->uri,
295152
      * and the vhost's list of locations hasn't changed, we can skip
295152
@@ -1486,7 +1499,7 @@ AP_DECLARE(int) ap_location_walk(request_rec *r)
295152
                     pmatch = apr_palloc(rxpool, nmatch*sizeof(ap_regmatch_t));
295152
                 }
295152
 
295152
-                if (ap_regexec(entry_core->r, entry_uri, nmatch, pmatch, 0)) {
295152
+                if (ap_regexec(entry_core->r, r->uri, nmatch, pmatch, 0)) {
295152
                     continue;
295152
                 }
295152
 
295152
@@ -1496,7 +1509,7 @@ AP_DECLARE(int) ap_location_walk(request_rec *r)
295152
                         apr_table_setn(r->subprocess_env,
295152
                                        ((const char **)entry_core->refs->elts)[i],
295152
                                        apr_pstrndup(r->pool,
295152
-                                       entry_uri + pmatch[i].rm_so,
295152
+                                       r->uri + pmatch[i].rm_so,
295152
                                        pmatch[i].rm_eo - pmatch[i].rm_so));
295152
                     }
295152
                 }