Skip to content

handle inside handle_errors does not work if handle_errors <status code> is used #6957

Open
@bludevsk

Description

@bludevsk

I tried to create language dependent custom 404 error pages with the following configuration:

handle_errors 404 {
    handle /de/* {
        respond "404 Fehler" 404
    }
    handle /en/* {
        respond "404 Error" 404
    }
    handle {
        respond "404 Fehler" 404
    }
}

But this does not work. It will always evaluate the directives in the first handle block. I also tried named matchers with different matchers (path, path_regexp, file) it always runs the first handle block.

I solved my problem by using the following slightly more complex version which works as excpected:

handle_errors {
    @404 `{err.status_code} == 404`
    handle @404 {
        handle /de/* {
            respond "404 Fehler" 404
        }
        handle /en/* {
            respond "404 Error" 404
        }
        handle {
            respond "404 Fehler" 404
        }
    }
}

The problem was consistent reporducable on
OS: Debian Buster
Caddy version: v2.9.0 h1:rteY8N18LsQn+2KVk6R10Vg/AlNsID1N/Ek9JLjm2yE=
and
OS: Ubuntu 24.04 (WSL)
Caddy version: v2.9.1 h1:OEYiZ7DbCzAWVb6TNEkjRcSCRGHVoZsJinoDR/n9oaY=

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞Something isn't workinghelp wanted 🆘Extra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions