Is regex allow for templates directive?

1. Caddy version (caddy version):

$ caddy version                                 
v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

2. How I run Caddy:

caddy run -adapter caddyfile -config caddyfile

a. System environment:

MasOS 10.15.6, brew install

b. Command:

caddy run -adapter caddyfile -config caddyfile

c. Service/unit/compose file:

n/a

d. My complete Caddyfile or JSON config:

{
	admin off
	auto_https disable_redirects
	http_port 1314
}

http://localhost:1314 {
	file_server
	root * {env.PWD}/www

templates (/blog)?/myip/?
}

3. The problem I’m having:

All pages processed by template.

4. Error messages and/or full log output:

n/a

5. What I already tried:

If I separate them they work correctly.

templates /myip/
templates /blog/myip/

6. Links to relevant resources:

Before I paste a wall of text here. Is regex allow for templates directive?

If you want to use regexp matching, you need to use a named matcher. Read more about it here:

1 Like

FYI it’s not necessary to use an env here, you can simply do this:

root www

The root path is relative unless the path starts with /. And if the path does not start with / then the * is not necessary.

1 Like

ok, I was suspecting I have to use named matcher, but validator did not throw any error :joy:

root www

Is that relative to where I run caddy command, or relative to the caddyfile?

Relative to where you run the command.

No error is thrown because it’s technically still a valid path matcher as long as it’s a single token that starts with a /.

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