Fix middleware redirects