Want a function that like “alias” in apache : Mapping URLs to Filesystem Locations

1. Caddy version (caddy version):

Caddy2(latest version)

2. How I run Caddy:

in site’dir enter:

caddy2 run

a. System environment:

systemd CentOS

b. Command:

paste command here

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

paste config here, replacing this text
use `caddy fmt` to make it readable
DO NOT REDACT anything except credentials
or helpers will be sad

3. The problem I’m having:

Mapping URLs to Filesystem Locations , Like “alias” in apache.

Such as:
DocumentRoot www.example.com
when enter www.example.com , jump to site1(/etc/www/var/site1).
when enter www.example.com/site2 , jump to site2(/root/site2).
site1 and site2 have different DoccumentRoot.

I enter a web address

4. Error messages and/or full log output:


5. What I already tried:

caddy config key word : rewrite , but only mapping to DocumentRoot.
double {…} in one configfile , but one caddy only one useful config , I want to two configfiles in different site.

6. Links to relevant resources:



You probably want something like this:

www.example.com {
	handle_path /site2* {
		root * /root/site2

	handle {
		root * /etc/ww/var/site1

thank for your reply , your reply must write config
in one configfiles , best have two configfile. one in /root/site2 , other in /etc/www/var/site1.
if have to one configfile , it is OK.

You can use import to load other config files from your main Caddyfile:

1 Like

thanks a million!

1 Like

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