Caddy - strip trailing slash

·Tech·No AI

If you’re using the Caddy (v2) server and want to remove a trailing slash from URLs (as on this blog), use redir

example.com {
root * /srv/example.com
encode zstd gzip
header {
Cache-Control max-age=3600
}
@noSlash path_regexp trailingSlash ^(.+)/$
redir @noSlash {re.trailingSlash.1} 301
// ...
}

Spot something wrong?

Found a typo, a broken link, or something that could be better? I would love to hear from you. Drop me a message and I will fix it.