Symfony redirect to external URL Symfony redirect to external URL symfony symfony

Symfony redirect to external URL


Answer to your question is in official Symfony book.

http://symfony.com/doc/current/book/controller.html#redirecting

public function indexAction(){    return $this->redirect('http://stackoverflow.com');    // return $this->redirect('http://stackoverflow.com', 301); - for changing HTTP status code from 302 Found to 301 Moved Permanently}

What is the "URL"? Do you have really defined route for this pattern? If not, then not found error is absolutelly correct. If you want to redirect to external site, always use absolute URL format.


You have to use RedirectResponse instead of Response

use Symfony\Component\HttpFoundation\RedirectResponse;

And then:

return new RedirectResponse('http://your.location.com');