How to redirect a path?

How to redirect a path like following?

redirect from /db/* to /db/mongodb/*.

Why path_regexp is unrecognized?

1. Caddy version (caddy version):

v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

My Caddyfile {
        root * /root/webroot
        encode gzip
        path_regexp mongodb  (^m.*mongo.*\/$)
        redir /dt/{re.mongo.1} /dt/mongodb/{re.mongo.1}

a. System environment:

Ubuntu 20.04.1 (no docker)

b. Command:

./caddy reload
2022/02/09 05:26:03.194	INFO	using adjacent Caddyfile
reload: adapting config using caddyfile: Caddyfile:33: unrecognized directive: path_regexp```

I think you forgot the matcher name: Request matchers (Caddyfile) — Caddy Documentation

My need is that redirect from /db/* to /db/mongodb/* ,
but I don’t know how to do it.

redir <matcher> to

As Matt said, you’re not using the correct syntax to define a named matcher. Please review the docs he linked.

Your regexp is also incorrect. You probably want something like this:

@mongo path_regexp mongo ^/db/(.*)
rewrite @mongo /db/mongodb/{re.mongo.1}

Thank you!

Thanks Francis; I was mobile so typing out the whole solution would have been a bit tedious. So I’m glad you did!


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