Remove special characters from uri

1. Caddy version (caddy version):

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

2. How I run Caddy:

caddy run

a. System environment:

Debian GNU/Linux 10

b. Command:

caddy run

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

(to-lower) {
        @{args.1} path_regexp {args.1} (.*)\.{args.0}
        redir @{args.1} {re.{args.1}.1}.{args.1}
}


domain.com {
 import to-lower JPG jpg
        import to-lower JPEG jpeg
        import to-lower PNG png
        import to-lower GIF gif

        uri replace "%20" "-"
        uri replace " " "-"
        uri replace "(" ""
        uri replace ")" ""

  #    uri replace "[\?\[\]\/\\\\=\<\>\:\;\,\"\'\&\$\#\*\(\)\|\~\`\!\{\}\%\+\]" ""

  reverse_proxy 10.10.10.101 {
        header_up X-Forwarded-Proto https
        header_up X-Forwarded-Port 443
        }

3. The problem I’m having:

I would like to remove all special characters from this regex from the file requests:

[?[]/\\=<>:;,"’&$#*()|~`!{}%+]

They shouldn’t be replaced just removed.

4. Error messages and/or full log output:

5. What I already tried:

I have been trying to get this working for a single char:
uri replace “(” “”

But that doesn’t do anything at all it seems

6. Links to relevant resources:

This should be possible since v2.4.0 with uri path_regexp

Maybe with:

uri path_regexp "[?[]/\\=<>:;,\"’&$#*()|~`!{}%+]" ""

Many thanks @francislavoie

I just upgraded to the latest version to test your suggestion:
v2.4.0 h1:yHnnbawH2G3ZBP2mAJF4XBLnJanqhULLP/wu01Qi9Io=

And edited my own regexp to:

uri path_regexp "[?[\]\\=<>;,\"'&$#*()|~`!{}%+]" ""

Which is now working perfectly as expected.

1 Like

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