Mapping Domains To Directories via a file (RewriteMap)

I would like to move a server over from apache to caddy, but it uses RewriteMap to assign a domain to a directory based on the contents of a text file. The file looks like this:

domain1.com /home/webserverfiles/somedirectory
xyz.com /home/webserverfiles/whatever
rocket.io /home/webserverfiles/abcdefg

and can be updated dynamically (adding or removing entries) without restarting apache.

Does caddy have this ability?

Yeah, you can do this with the map directive:

domain1.com, xyz.com, rocket.io {
	map {host} {root} {
		domain1.com /home/webserverfiles/somedirectory
		xyz.com /home/webserverfiles/whatever
		rocket.io /home/webserverfiles/abcdefg
	}

	root * {root}

	...
}

You just need to reload Caddy after modifying the config (no downtime). You can break this out into a separate file with import.

2 Likes

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