Mapped variable in path_regexp matcher

1. The problem I’m having:

http://mysite:8080 {
        map {uri} {blogname} {
                ~(/[^/]+/)files/(.*) "${1}"
        }

        map {blogname} {blogid} {
                / 1
                /eng/ 2
                default -99999

                #Ref: http://wordpress.org/extend/plugins/nginx-helper/
                #include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ;
        }
    uri path_regexp ^{blogname}files/(.+)$ "/wp-content/blogs.dir/{blogid}/files/$1"
    reverse_proxy 127.0.0.1:8081

blogname variable in path_regexp not working
if i replace it with just “/eng/” (hardcoded) all works as expected
is it possible at all to use variables in this place?

3. Caddy version:

caddy version
v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

4. How I installed and ran Caddy:

yum install yum-plugin-copr yum copr enable @caddy/caddy yum install caddy

a. System environment:

centos 7

linkes

i need to recreate this “files” to “blogs.dir” mapping
say we have 10 sites in multisite with sub dirs

1 Like

Unfortunately, no, placeholders aren’t replaced in regexp find strings because they get compiled at config load time for maximum performance.

I’m not sure what workaround to suggest right now. Maybe @matt has some ideas.

That’s correct; regex are compiled at load-time for performance.

The path_regexp is doing three things: matching a URI path, extracting a value, and rewriting the URI. You may want to try splitting those two so you can use a placeholder for matching, the regexp for extracting, and the variable for rewriting.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.