Trailing Slash
All core middleware lives in the middleware package:
import "github.com/labstack/echo/v5/middleware"When configured to redirect, the trailing slash middlewares percent-encode
control characters in the path before constructing the Location header.
Add trailing slash
Section titled “Add trailing slash”Add trailing slash middleware adds a trailing slash to the request URI.
e := echo.New()e.Pre(middleware.AddTrailingSlash())Remove trailing slash
Section titled “Remove trailing slash”Remove trailing slash middleware removes a trailing slash from the request URI.
e := echo.New()e.Pre(middleware.RemoveTrailingSlash())Custom configuration
Section titled “Custom configuration”e := echo.New()e.Use(middleware.AddTrailingSlashWithConfig(middleware.AddTrailingSlashConfig{ RedirectCode: http.StatusMovedPermanently,}))The example above adds a trailing slash to the request URI and redirects with
301 - StatusMovedPermanently.
Configuration
Section titled “Configuration”AddTrailingSlashConfig · github.com/labstack/echo/v5@5196b9b
RemoveTrailingSlashConfig · github.com/labstack/echo/v5@5196b9b