Replacing specific character in a file name when using reverse proxy

1. The problem I’m having:

I am using reverse proxy to deliver an embedded web system I can’t really control the content of, however the system is occasionally trying to serve up a file that starts with a period. Because this ends up being hidden on the file system, the embedded web server won’t serve it.

All files that start with a . are available on the file system without the period as I am running a manual task to copy them, so for example /tiles/faces/.happy.png is also available on the file system as /tiles/faces/happy.png.
I would like to rewrite the URL request for these images so when the webpage tries to load that image, it gets redirected and doesn’t fail to load it.

I tried the rewrite config seen below but when this is in effect - NO content loads.

2. Error messages and/or full log output:

NA, server starts normally.

3. Caddy version:


4. How I installed and ran Caddy:

Followed instructions on install website. Install — Caddy Documentation

a. System environment:

Ubuntu 20.04.

b. Command:

NA, starting as system service. Can run with -run /etc/caddy/Caddyfile on command line if required for testing, and gives the same results; but that’s not what is in use in production. Outcome is the same for both service and command line.

c. Service/unit/compose file:


d. My complete Caddy config: {

@facetiles path_regexp facetiles ^.*\/\.(.*.png)

handle @facetiles {
        rewrite /tiles/faces/* /tiles/faces/{re.facetiles.1}

That’s quite an old version. Please upgrade to the latest, 2.7.6

Is that really your entire config? It looks incomplete.

I would write the regexp like this maybe:

@facetiles path_regexp facetiles ^/tiles/faces/\.(.*)$
rewrite @facetiles /tiles/faces/{re.facetiles.1}

Enable the debug global option and show your logs. It’ll show the rewrites that happen (original path and rewritten path).

Yes that is/was my entire config - only using it for one thing. Your suggestion worked. Thanks.

The problem is you’re missing handling for requests that don’t match your existing matchers. That means Caddy will serve empty 200 status responses to non-matching requests. You should put something in your config to handle those cases (e.g. a handle with no matcher as fallback).


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