Fix bug in trailing slash handler middleware

Both middleware for handling trailing slashes were not handling query
strings properly.