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:

Null

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:

https://httpd.apache.org/docs/2.4/urlmapping.html

THANK FOR TOUR HELP!!!

You probably want something like this:

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

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

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.