Middleware ->withRedirect


#1

Within my middleware and running Slim 3.8.1 this would indeed redirect:
return $response->withRedirect($this->router->pathFor('user.login'), 403);

After upgrading to 3.10.0 that same redirect returns not output, just a blank screen.
When removing the HTTP status code it works again.

What has changed?


#2

Browsers don’t expect a location header with a non 3xx response. I made a similar mistake. If the redirect is more important than the status code (which a user doesn’t see in a web app) then you will need to use a 3xx status code (like 302) or just remove the status code.

return $response->withRedirect($this->router->pathFor('user.login'));

#3

Thanks for the information tflight.