Exclude path from redirect

The problem I’m having:

Hey Caddy community.

I have the following in my Caddyfile:

www.mydomain.com {
    handle /google1234567890.html {
         file_server
    }

    encode zstd gzip
    reverse_proxy my-frontend:3000

    import redirects/myredirects

}

in redirects/myredirects there is a rule that redirects paths with a .html suffix to the same path without it:
@htmlSuffix path_regexp htmlSuffix ^(.*).html$
redir @htmlSuffix {http.regexp.htmlSuffix.1}

Now i would like to exclude the /google1234567890.html path, since it’s a verification file for google that needs to be accessible WITH .html suffix.

How can this be achieved?
I’ve tried regex with negative lookahead, but that doesn’t seem to be supported :frowning:

Caddy version:

2.8

Following combination of request matchers solved my problem:

@htmlRedirects {
    not {
        path /google1234567890.html
    }
    path_regexp htmlSuffix ^(.*)\.html$
}
redir @htmlRedirects {re.htmlSuffix.1}

:victory_hand:

1 Like

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