From bc8431b198873ddad4d5723bd3fff9e8ceb4774e Mon Sep 17 00:00:00 2001 From: Graham Leggett Date: Mon, 17 Jul 2023 15:25:13 +0000 Subject: [PATCH] mod_alias: Add AliasPreservePath directive to map the full 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 | 3 ++ docs/manual/mod/mod_alias.xml | 43 +++++++++++++++++++++++++ modules/mappers/mod_alias.c | 13 +++++++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 changes-entries/alias-preserve-path.txt diff --git a/changes-entries/alias-preserve-path.txt b/changes-entries/alias-preserve-path.txt new file mode 100644 index 00000000000..30eb4df3816 --- /dev/null +++ b/changes-entries/alias-preserve-path.txt @@ -0,0 +1,3 @@ + *) mod_alias: Add AliasPreservePath directive to map the full + path after the alias in a location. [Graham Leggett] + diff --git a/docs/manual/mod/mod_alias.xml b/docs/manual/mod/mod_alias.xml index 3ca3a7f0495..463c1eddf8c 100644 --- a/docs/manual/mod/mod_alias.xml +++ b/docs/manual/mod/mod_alias.xml @@ -194,6 +194,24 @@ Alias "/image" "/ftp/pub/image" </LocationMatch> +

Note that when the AliasPreservePath + 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.

+ + +# /files/foo and /files/bar mapped to /ftp/pub/files/foo and /ftp/pub/files/bar +<Location "/files"> + AliasPreservePath on + Alias "/ftp/pub/files" +</Location> +# /errors/foo and /errors/bar mapped to /var/www/errors.html +<Location "/errors"> + AliasPreservePath off + Alias "/var/www/errors.html" +</Location> + + @@ -641,5 +659,30 @@ ScriptAliasMatch "(?i)^/cgi-bin(.*)" "/usr/local/apache/cgi-bin$1" + +AliasPreservePath +Map the full path after the alias in a location. +AliasPreservePath OFF|ON +AliasPreservePath OFF +server configvirtual host +directory + +2.5.1 and later + + +

When using the two parameter version of the + Alias directive, the full path after the alias + is preserved. When using the one parameter version of the + Alias directive inside a + Location directive, the full path is dropped, + and all URLs are mapped to the target expression.

+ +

To make the one parameter version of the + Alias directive preserve paths in the same way + that the two parameter version of the Alias + directive, enable this setting.

+ +
+
diff --git a/modules/mappers/mod_alias.c b/modules/mappers/mod_alias.c index b1638a34e42..cd9db1f8400 100644 --- a/modules/mappers/mod_alias.c +++ b/modules/mappers/mod_alias.c @@ -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} };