All Collections SSL & Caddy Custom Redirects

Custom Redirects

Caddy can be configured to do custom redirects and other fancy rewriting before requests hit your application.

Updated

Redirect to WWW

In your app's settings, you can use the following matcher and redirect directive to match domains and redirect to the www version.

@nonwww host example.com example2.com
redir @nonwww https://www.{host}{uri} permanent

%{default}

Redirect to Non-WWW

Similarly, we can match against the www subdomain and redirect to the root domain instead.

@nonwww host www.example.com
redir @nonwww https://example.com{uri} permanent

%{default}