Redir all domain/subdomain non-www to www

I’ve got new related problem. this is my current caddyfile:

 # Main domain
 http://example.com, https://example.com {
     redir www.example.com
     tls name@example.com
 }

 www.example.com {
     root /site/example
     gzip
 }

 # Subdomains
 http://*.example.com, https://*.example.com {
     redir www.{label1}.example.com
     tls name@example.com
 }

 www.sub1.example.com {
     proxy / localhost:8888 {
         transparent
     }
 }

 www.sub2.example.com {
     proxy / localhost:19999 {
         transparent
     }
 }

so currently the webserver only works if accessed through the full https://www.example.com or https://www.sub1.example.com

trying to access incomplete address will result in infinite 301 redir e.g.

curl -IL https://example.com
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: /www.example.com
Server: Caddy
Date: Fri, 30 Mar 2018 19:47:48 GMT

looping infinitely

and

curl -IL http://sub1.example.com
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: /www..example.com  <- notice the double dots
Server: Caddy
Date: Fri, 30 Mar 2018 21:23:59 GMT

looping infinitely

please let me know how to fix this or if you have other improvements to my caddyfile

thanks.