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('http://www.belchamber.us/page-to-redirect', array(), 301);  // 301 is where you can also specify 302
}

 

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

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