Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

beforeNotFoundAction redirecting

Can anyone tell me how can you do a redirect from this event? I cannot do that.



84.5k

This way:

public function beforeNotFoundAction()
{
    $this->response->redirect("location");
    return false;
}


19.6k

Ah, my bad, I haven't realized that I did the wrong question. What I want is to redirect, but before that, use setStatusCode(). The problem is that, even with setNotModified(), the statusCode is deleted.



84.5k
Accepted
answer

Phalcon\Http\Response::redirect automatically sets up a 301/302 status code which is the right way to perform a redirection: http://en.wikipedia.org/wiki/HTTP%5301

You can pass the status code in the third parameter:

$response->redirect("http://www.example.com/new-location", true, 304);

https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/http/response.zep#L333



19.6k

Ah well, nevermind. I forgotted that I was redirecting, so setting a 404 doesn't makes sense. Thanks.