Caddyfile snippets


(Eduardo Perroud) #1

Hello, I am trying to create some snippets to improve my work.
Which model is better or work on Caddy?
I don’t know if snippets can be loaded into snippets.

common snippet

(snippet1) {
	redir 308 {
		if {host} match (?:www\.)(.*)
		/ https://{$1}
	}
}

model 02

(conditional-redirect) {
	if {host} match (?:www\.)(.*)
	/ https://{$1}
}

and then:

(snippet2) {
	redir 308 {
		import conditional-redirect
	}
}

Is it possible?

Another questions:

  1. using placeholder {status}, how to check if browser supports http code 308 or 301, such as 307 and 302? Any idea?
  2. What the real difference between {host} and {hostonly}? Ok, I know about the port information, but the string is the same if the port is common 80/443, no?
  3. The http.on can be used to call a .sh file?

Thank you very much.


(Matthew Fay) #2

Doesn’t look like snippets are allowed in snippets, no. They also aren’t allowed inside other directives - import has to be a top-level directive.

  1. I don’t believe it’s necessary to check if a browser supports 307 and 308 status codes.
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307#Browser_compatibility
    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308#Browser_compatibility
  2. That’s pretty much it, yep.
  3. As long as the .sh is executable, it should work, yep.

(system) #3

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.