From c939d6ef190285ba1c286c9ad3ce4c8cca386ebf Mon Sep 17 00:00:00 2001 From: Robert L Mathews Date: Thu, 10 Jul 2025 12:01:41 -0700 Subject: [PATCH] Remove restriction that prevents use of ap_expr expressions in Redirects outside of Currently, it's not possible to use expression syntax like this in (say) .htaccess files: Redirect 301 https://%{HTTP_HOST}%{REQUEST_URI} You have to instead use a much uglier RewriteCond/RewriteRule. The reason it doesn't work is not because the code doesn't exist, but because mod_alias.c restricts expressions in redirects to " context only for now". It's not clear why that restriction was/is needed. I asked if anyone knew the reason for it on the httpd dev mailing list in 2022, but nobody replied: https://lists.apache.org/thread/m72z147c3rffpk7goy7n0z66l7jw16lc My company has been running this patch on many production servers for three years with no trouble. It allows the above example to work as expected from a .htaccess file, which seems generally useful and in accordance with the "ongoing effort to only use a single variant, called ap_expr, for all configuration directives". --- modules/mappers/mod_alias.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/mappers/mod_alias.c b/modules/mappers/mod_alias.c index cd9db1f8400..ff4968cf47a 100644 --- a/modules/mappers/mod_alias.c +++ b/modules/mappers/mod_alias.c @@ -301,11 +301,7 @@ static const char *add_redirect_internal(cmd_parms *cmd, * if we understand the first arg but have no second arg, we are dealing * with a status like "GONE" or a non-redirect status (e.g. 404, 503). */ - if (!cmd->path) { - /* context only for now */ - ; - } - else if ((grokarg1 > 0 && arg2 && !arg3) || (!grokarg1 && !arg2)) { + if ((grokarg1 > 0 && arg2 && !arg3) || (!grokarg1 && !arg2)) { const char *expr_err = NULL; url = grokarg1 ? arg2 : arg1;