|
|
|
|
|
by mholt
1377 days ago
|
|
The uri directive can strip_prefix, strip_suffix, or do substring replacements: https://caddyserver.com/docs/caddyfile/directives/uri It can also do regex replacements on the path portion of the URI. And yes, these are internal rewrites since uri is a directive that wires up the rewrite handler. We actually have a special section in the docs all about enforcing trailing slashes, including external redirects: https://caddyserver.com/docs/caddyfile/patterns#trailing-sla... Note that the file_server will automatically enforce canonical URIs, including redirecting to add or remove the trailing slash according to whether the resource is a file or a directory. To redirect many unspecified paths, your regex is probably the best way to do it for now. Feel free to open an issue to propose an alternative! |
|
I'll follow up with issues tomorrow (I think an issue for updating the common caddyfile patterns bit on the website also makes sense - I suspect a blanket rule for removing trailing slashes is more likely to be a common pattern people seek a solution for than removing a trailing slash on explicitly enumerated paths).