Symfony: Forcing redirects in controller and specifying redirect type

The Symfony documentation is getting better, but it still lacks more detail, which is why I’ve been collecting helpful tips and snippets here.  According to the Symfony docs, by default, the “redirectToRoute()" method performs a 302 (temporary) redirect, so in order to specify a 301 (permanent) redirect, you can add the third argument in this method within your controller and logic that would trigger a redirect.

public function indexAction()
    return $this->redirectToRoute('', array(), 301);  // 301 is where you can also specify 302



Leave a Reply

Your email address will not be published. Required fields are marked *