Bug 69239 - I need the result of a map lookup without having the root-prefix added
Summary: I need the result of a map lookup without having the root-prefix added
Status: RESOLVED CLOSED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_rewrite (show other bugs)
Version: 2.4.61
Hardware: All Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-08-02 09:51 UTC by niels
Modified: 2024-08-05 08:16 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description niels 2024-08-02 09:51:10 UTC
In change 9494aa8 the following code was added:
        }
        else if (!(p->flags & (RULEFLAG_PROXY | RULEFLAG_FORCEREDIRECT))) {
            /* Not an absolute URI-path and the scheme (if any) is unknown,
             * and it won't be passed to fully_qualify_uri() below either,
             * so add an implicit '/' prefix. This avoids potentially a common
             * rule like "RewriteRule ^/some/path(.*) $1" that is given a path
             * like "/some/pathscheme:..." to produce the fully qualified URL
             * "scheme:..." which could be misinterpreted later.
             */
            rewritelog(r, 3, ctx->perdir, "add root prefix: %s -> /%s",
                       newuri, newuri);

            newuri = apr_pstrcat(r->pool, "/", newuri, NULL);
        }

I have rules that look up a map and based on the key a path is generated. But since the look up result isn't an absolute URI-path and does not have a scheme, the root-prefix gets added.
The rule looks like this:
RewriteRule ^ ${redir-map:${tolower-map:%{HTTP_HOST}}}

and the lookup results in a user-name on that system.
Later rules will construct a URL which needs that user-name but with the added / the further rules break.

It would be great, if there would be any way to be able no not have this behavior interfer. Maybe a flag that can be set, so that the root prefix won't be added.
Comment 1 Yann Ylavic 2024-08-02 10:21:33 UTC
Didn't test it but maybe you could:
  RewriteRule ^ - [E=mylookup:${redir-map:${tolower-map:%{HTTP_HOST}}}]
and then use %{ENV:mylookup} for your next rules?
This would not pretend that the lookup is is uri-path thus avoid the new check.
Comment 2 niels 2024-08-05 08:15:28 UTC
Thanks that worked.