The caddy {labelN} placeholder is described as follows:
The Nth label of the host (where N is an integer, at least 1); examples: {label2} of “sub.example.com” is “example”. {label1} of “*.example.com” is the subdomain portion only.
Unfortunately, the label numbers are assigned from left-to-right, rather than from right-to-left. For example, here are the label numbers for various domain/sub-domain combinations under the current (left-to-right) eval implementation:
caddy.com: label1=caddy, label2=com
www.caddy.com: label1=www, label2=caddy, label3=com
admin.www.caddy.com: label1=admin, label2=www, label3=caddy, label4=com
By contrast, right-to-left assignment would result in more consistent output (see label1 and label2):
caddy.com: label1=com, label2=caddy
www.caddy.com: label1=com, label2=caddy, label3=www
admin.www.caddy.com: label1=com, label2=caddy, label3=www, label4=admin
Right-to-left assignment enables many common configuration scripting use-cases. For example, the following rather useful auto-placeholder is currently impossible under current assignment rules:
caddy.com www.caddy.com admin.www.caddy.com {
root /www/web site/caddy.com
# auto-generate of "/www/weblogs/caddy.com/access.log" that works
# for the above block is not possible under left-to-right eval...
log / /www/weblogs/{labelX}.{labelY}/access.log
# but this would always work, if {labelN} were right-to-left assigned;
# the result would always be "caddy.com" regardless of conn host:
log / /www/weblogs/{label2}.{label1}/access.log
}
By contrast, if the {labelN} placeholder were assigned right-to-left, the above would work regardless of the number of levels of sub-domains present in the domain block directive.
Is there a chance you would consider having the {labelN} placeholder eval in a direction (right-to-left) which results in more useful output?