One of the solutions I found is to use request.env ["REQUEST_URI"], which contains the raw URL sent with the request. Unfortunately, since it is not a direct string property of a request, it requires a custom mapping object :
class TrailingSlashMatcher
def matches?(request)
uri = request.env["REQUEST_URI"]
!!uri && uri.end_with?("/")
end
end
AppName::Application.routes.draw do
match '/example/*path', constraints: TrailingSlashMatcher.new, to: redirect("/somewhere/")
end
This seems like an overkill, so hopefully someone has a more elegant approach.
source
share