]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_alias: Add AliasPreservePath directive to map the full
authorGraham Leggett <minfrin@apache.org>
Mon, 17 Jul 2023 15:25:13 +0000 (15:25 +0000)
committerGraham Leggett <minfrin@apache.org>
Mon, 17 Jul 2023 15:25:13 +0000 (15:25 +0000)
path after the alias in a location.

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

changes-entries/alias-preserve-path.txt [new file with mode: 0644]
docs/manual/mod/mod_alias.xml
modules/mappers/mod_alias.c

diff --git a/changes-entries/alias-preserve-path.txt b/changes-entries/alias-preserve-path.txt
new file mode 100644 (file)
index 0000000..30eb4df
--- /dev/null
@@ -0,0 +1,3 @@
+  *) mod_alias: Add AliasPreservePath directive to map the full
+     path after the alias in a location. [Graham Leggett]
+
index 3ca3a7f04959fcab4ce4ab76487de9d4c636cfa1..463c1eddf8c058adf69cd4cdeb0237dfa9f22747 100644 (file)
@@ -194,6 +194,24 @@ Alias "/image" "/ftp/pub/image"
 &lt;/LocationMatch&gt;
     </highlight>
 
+    <p>Note that when the <directive>AliasPreservePath</directive>
+    directive is on, the full path is mapped to the destination. When
+    the directive is off, all URLs are mapped to the single target
+    URL.</p>
+
+    <highlight language="config">
+# /files/foo and /files/bar mapped to /ftp/pub/files/foo and /ftp/pub/files/bar
+&lt;Location "/files"&gt;
+    AliasPreservePath on
+    Alias "/ftp/pub/files"
+&lt;/Location&gt;
+# /errors/foo and /errors/bar mapped to /var/www/errors.html
+&lt;Location "/errors"&gt;
+    AliasPreservePath off
+    Alias "/var/www/errors.html"
+&lt;/Location&gt;
+    </highlight>
+
 </usage>
 </directivesynopsis>
 
@@ -641,5 +659,30 @@ ScriptAliasMatch "(?i)^/cgi-bin(.*)" "/usr/local/apache/cgi-bin$1"
 </usage>
 </directivesynopsis>
 
+<directivesynopsis>
+<name>AliasPreservePath</name>
+<description>Map the full path after the alias in a location.</description>
+<syntax>AliasPreservePath OFF|ON</syntax>
+<default>AliasPreservePath OFF</default>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context>
+</contextlist>
+<compatibility>2.5.1 and later</compatibility>
+
+<usage>
+    <p>When using the two parameter version of the
+    <directive>Alias</directive> directive, the full path after the alias
+    is preserved. When using the one parameter version of the
+    <directive>Alias</directive> directive inside a
+    <directive>Location</directive> directive, the full path is dropped,
+    and all URLs are mapped to the target expression.</p>
+
+    <p>To make the one parameter version of the
+    <directive>Alias</directive> directive preserve paths in the same way
+    that the two parameter version of the <directive>Alias</directive>
+    directive, enable this setting.</p>
+
+</usage>
+</directivesynopsis>
 
 </modulesynopsis>
index b1638a34e4226bd73825c5d71368e6bd0814feaa..cd9db1f8400c960d6a2dd80d1e94acf115eebd58 100644 (file)
@@ -41,6 +41,8 @@
 #define ALIAS_FLAG_OFF 0
 #define ALIAS_FLAG_ON  1
 
+#define ALIAS_PRESERVE_PATH_DEFAULT 0
+
 typedef struct {
     const char *real;
     const char *fake;
@@ -64,6 +66,7 @@ typedef struct {
     const ap_expr_info_t *redirect;
     int redirect_status;                /* 301, 302, 303, 410, etc */
     int allow_relative;                 /* skip ap_construct_url() */
+    int alias_preserve_path;            /* map full path */
 } alias_dir_conf;
 
 module AP_MODULE_DECLARE_DATA alias_module;
@@ -89,6 +92,7 @@ static void *create_alias_dir_config(apr_pool_t *p, char *d)
     (alias_dir_conf *) apr_pcalloc(p, sizeof(alias_dir_conf));
     a->redirects = apr_array_make(p, 2, sizeof(alias_entry));
     a->allow_relative = ALIAS_FLAG_DEFAULT;
+    a->alias_preserve_path = ALIAS_FLAG_DEFAULT;
     return a;
 }
 
@@ -124,6 +128,10 @@ static void *merge_alias_dir_config(apr_pool_t *p, void *basev, void *overridesv
     a->allow_relative = (overrides->allow_relative != ALIAS_FLAG_DEFAULT)
                                   ? overrides->allow_relative 
                                   : base->allow_relative;
+    a->alias_preserve_path = (overrides->alias_preserve_path != ALIAS_FLAG_DEFAULT)
+                                  ? overrides->alias_preserve_path
+                                  : base->alias_preserve_path;
+
     return a;
 }
 
@@ -443,7 +451,7 @@ static char *try_alias(request_rec *r)
             return PREGSUB_ERROR;
         }
 
-        if (dirconf->alias_fake) {
+        if (dirconf->alias_fake && dirconf->alias_preserve_path == ALIAS_FLAG_ON) {
             int l;
 
             l = alias_matches(r->uri, dirconf->alias_fake);
@@ -764,6 +772,9 @@ static const command_rec alias_cmds[] =
     AP_INIT_FLAG("RedirectRelative", ap_set_flag_slot,
                   (void*)APR_OFFSETOF(alias_dir_conf, allow_relative), OR_FILEINFO,
                   "Set to ON to allow relative redirect targets to be issued as-is"),
+    AP_INIT_FLAG("AliasPreservePath", ap_set_flag_slot,
+                  (void*)APR_OFFSETOF(alias_dir_conf, alias_preserve_path), OR_FILEINFO,
+                  "Set to ON to map the full path after the fakename to the realname."),
 
     {NULL}
 };