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
// ...
}
uptime
8,215 days · since 2004
posts
294 · busiest 2026 (64)
words
~143,065 · ~10 h read
topics
tech 239 · personal 55
langs
en 229 · pl 65
written
211 by hand · 83 AI-assisted
projects
3
build
ca50768 · 2026-06-30