Rewrite adding headers and URL params

1. Caddy version (caddy version): v2.3.0

2. How I run Caddy:

a. System environment:

Via docker on Google’s Container Optimized OS, caddy:2-alpine image.

b. Command:

I don’t have the original docker run command I used but it was something like

docker run --name=caddy --volume=/var/data/caddy/Caddyfile:/etc/caddy/Caddyfile -p 443:443 -p 80:80 caddy:2-alpine

c. Service/unit/compose file:


d. My complete Caddyfile or JSON config:

    email xxxxxxxx

db.xxxxxxxx {

    @adminlogin {
        path /admin/login/*
        query password=*
    handle @adminlogin {
        request_header +Authorization "Basic XXXXXXXX"
        rewrite * /admins/_design/admin/_update/login/{path}
    reverse_proxy couchdb:5984

3. The problem I’m having:

Hello there.
I’m trying to expose a couple of endpoints from a CouchDB database that requires Basic HTTP authentication. This works perfectly for every endpoint that doesn’t have any parameters appended to the URL.
For this specific case, I need for the URL https://db.xxxxxxxx/admin/login/some_id that includes a query param password to be rewrited to https://db.xxxxxxxx/admins/_design/admin/_update/login/some_id, keeping the query parameters and adding the basic authentication header with the token hardcoded.
I think the only thing is not working is appending the some_id param to the rewrite destination.

Thank you so much!

4. Error messages and/or full log output:

No errors.

5. What I already tried:

6. Links to relevant resources:

Please don’t forget to make a volume for the /data directory, else you risk data loss and hitting rate limits. See Docker Hub

You’ll want to use a path_regexp matcher instead then, to capture the part of the URL your need to preserve before the rewrite. Cause right now, if you rewrite with {path}, then it appends the entire existing path to the end of your added prefix.

So for a request like /admin/login/foo, you’ll end up with /admins/_design/admin/_update/login//admin/login/foo.

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