redirects in caddy

This commit is contained in:
Kulvir Singh
2025-10-15 01:56:24 +05:30
parent 9e916cfec7
commit 88e6efbd90

View File

@@ -27,3 +27,18 @@ sudo systemctl reload caddy
```
Now visit `domain-name.com` again and it will be serving site over HTTPS.
Caddy will automatically provision and renew TLS certificates from [LetsEncrypt](https://letsencrypt.org)
## Redirects
You might want to setup few redirects to your root domain for like IP Address and `www` sub domain.
```Caddyfile
192.168.1.1,
www.domain-name.com {
redir https://domain-name.com{uri}
}
```
You can setup this rule for multiple domains by either writing them space seperated or comma seperated as above.
`{uri}` specified at the end of domain name preserves the path from the URL user entered.
Now if anyone visits your website via server's IP address or using `www` subdomain they will be redirected to your root domain.
**It just looks cleaner.**