How to rewrite and set rootdir

Hello, I want to rewrite an url like mydomain.com/path to mydomain.com/inner and set rootdir for this url.
This can be done in nginx:

   location /path {
        rewrite ^/path(.*)$ /inner$1 break;
        root /home/user/inner;
    }

But I can’t figure out how to achieve this in caddy, is this possible?

You won’t be able to rewrite and have a separate root for the rewritten URI, but you could do it with a redirect instead.

The other option is to structure your file system appropriately so that the inner folder is directly beneath the site root.

He might be able to accomplish something via a complicated combination of rewrites and http.filter plugin use, but it wouldn’t be performant.

I’m not sure you can. If my understanding is correct, the root directive sets the web root directly, so the last instance of it within a site definition “wins” (the previous declarations are discarded). You just can’t have two separate web roots in one site, so the only way to go about it would be to have one site for example.com, with its own root, and one site at example.com/path, with another web root.

Yeah, maybe if the second root was entirely contained within the first, but that doesn’t make sense. Caddy lacks the equivalent of a location directive because of how complicated it would be to integrate with things like Hugo plugin being able to create an entire static site on server start, etc. It’d be nice, though – and ultimately I think necessary.

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