Single uri redirection vs subdomain for separate base directory

1. The problem I’m having:

I’m struggling to understand the documentation surrounding URI redirection.

I’d like for:

https://artisanadaptations.com/staging/

to serve

/home/username/artisanadaptations.com/src/public/

and I would like

https://artisanadaptations.com/

to serve

/home/username/artisanadaptations.com/srv/

The reason I’d like for this so I can quickly preview changes in a very simple Hugo website without having to commit each change to what people will find on logging into the base URL.

I suppose I could do this with https://staging.artisanadaptations.com/ but I’d like to learn if this is at all possible this way with URL/rewrites.

2. Error messages and/or full log output:

n/a

3. Caddy version:

version:
alpinehostname# apk info caddy
caddy-2.6.4-r6 description:
Fast, multi-platform web server with automatic HTTPS

caddy-2.6.4-r6 webpage:
https://caddyserver.com/

caddy-2.6.4-r6 installed size:
41 MiB

4. How I installed and ran Caddy:

apk install caddy

a. System environment:

Alpine on a VPS

b. Command:

n/a

c. Service/unit/compose file:

n/a

d. My complete Caddy config:

n/a, looking for recommendations on how to configure this

5. Links to relevant resources:

See this article:

It is possible to do that, but your site in the subpath needs to be aware of being in a subpath, and all the links in the HTML need to have /staging as a prefix.

Since you’re using Hugo, there’s likely a way to configure it to generate URLs with a prefix everywhere. I think there’s a baseURL option you can configure.

That said, a subdomain is certainly the easiest solution.

That’s a pretty old version at this point. Please upgrade to the latest version, 2.7.5.

1 Like
root /staging/* /home/username/artisanadaptations.com/src/public
root * /home/username/artisanadaptations.com/srv

should do what you want, but as Francis said, beware the subfolder problem.

No not quite @matt because that would require the files to be in /home/username/artisanadaptations.com/src/public/staging.

You need handle_path to strip /staging from the URL before handling, if your files, if no /staging directory exists inside /public.

1 Like

Oh, I see what he meant now. Ok, yeah. handle_path would work for that, and/or the manual use of uri strip_prefix.

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