Fixed redirect in middleware