Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for redirects for paths with a trailing slash #1668

@satakuma

Description

@satakuma

Feature Request

Is your feature request related to a problem? Please describe.

I want to configure a 301 Moved Permanently redirect for paths with a trailing slash, for example I want a request to /path/ to be redirected to /path, and apply this to all routes used by the app.

Describe the solution you'd like

Configuration option normalize_paths. If set to true, Loco should add corresponding redirects for me.

Describe alternatives you've considered

AFAIK in Axum there are two options:

  1. Use RouterExt's route_with_tsr. It is not possible to use this trait when using Loco's Routes.
  2. Use NormalizePath middleware to remove the trailing slash before routing. This requires wrapping the middleware around the entire Router, which is not directly exposed by Loco's Hooks before serving. The only way to accomplish that I see is to override serve with my own impl. Also this does not directly achieve what I want, because it will route both paths to the same handler instead of issuing a redirect.

Since Routes API is public, I can also iterate over handlers and create redirects manually myself, but this seems tedious and it would be really nice to have support for this from the framework.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions